A while ago I started on a #Uxntal backend for my #Fortran source-to-source compiler.

The ultimate goal is to compile my #Funktal compiler into Uxntal, so that Funktal becomes a Uxn-native language. But that is still some way off.

As a detour, I created the necessary machinery to use Varvara devices in Fortran. It's now in a state that straight ports of `snake` and `bunnymark` work. I'm very happy about that.

I guess it was inevitable: I've started on a compiler from Fortran to Uxntal.

If I manage it, I will eventually be able to compile my Funktal compiler to Uxntal and so make Funktal a truly Uxn-native language.

But I expect it will be a long and tortuous road with many problems along the way. Fun, in other words.

#Uxn #Funktal

I wrote a blog post on how Funktal handles Uxn/Varvara I/O devices and state, with examples of a few GUI-based programs.

https://wimvanderbauwhede.codeberg.page/articles/funktal-devices-state/
#Funktal
#Uxn

More on Funktal: I/O devices and state

How Funktal programs can interact with I/O devices, and how mutable state helps with this.

Wim Vanderbauwhede

I had a little bit of time to do some more Funktal debugging, and now the snake game from the Uxn demos works as well.
So I think it's now ready for a write-up.

The source code size is about twice as big; the rom size is 3x larger, but it's still only 3KB.

https://codeberg.org/wimvanderbauwhede/funktal/src/branch/devel/examples/snake.ftal
#Uxn #Funktal

funktal

A small compiler implemented in Fortran for a statically typed functional language running on Uxn.

Codeberg.org
It's always exciting to get something working, and so I was really chuffed to day: Funktal is finally so far that I could implement the Uxn DVD Bounce demo, and it works! Here is a short video.
#Funktal #Uxn

Did some more work on Funktal, it now has support for mutable state. I added this because functions called to handle an event frequently need it.

The way it works is:

- define a type, e.g.
types {
Coords = UInt16 UInt16 MkCoords
}

- mark an instance as state:
state {
xy : Coords
}

- Optionally, create some convenience accessors to access the fields in the record. These are just integers.
constants {
x#Coords : UInt8 = 0x00
y#Coords : UInt8 = 0x01
}
#Funktal #Uxn

My little functional language for Uxn, Funktal, is finally in a state good enough for a blog post:

"Funktal: a frugal functional programming language"

https://wimvanderbauwhede.codeberg.page/articles/funktal/

You can also try it out:

https://codeberg.org/wimvanderbauwhede/funktal

#Funktal #Uxn

Funktal: a frugal functional programming language • Wim Vanderbauwhede

Funktal is a functional programming language for the 64 kB Uxn virtual machine.

I got recursion working in #Funktal, and now I can write this fixedpoint factorial:

-- the fixedpoint function
functions {
fix = (\f. f f apply )
}

main {
5
`(\ n <- f .
`(1)
`( n n 1 - f f apply * )
n 1 ==
if
) fix print
}

This actually works, even if it is still a bit rough around the edges.

Because #Funktal uses postfix expressions, there is no need for parentheses to group subexpressions. So I use the parentheses to delimit lambda functions. That is perhaps counter-intuitive but I prefer it over, say, [] or {}.

Funktal is strict, so any function gets applied right away. And it supports lambdas without arguments. So you can write something like

( 6 7 * )

and it will do the same as

6 7 *

but the parenthesised version is a function application.

Another #Funktal example:

types {
Bool = True | False
}

main {
`( 42 print ) `( 43 print ) True if
}

booleans in Funktal are just an ordinary sum type.
Lambdas with an argument are (\ ... . ...) but Funktal allows "lambdas" without argument, for computations that take no inputs.
the backtick means the expression is not evaluated but passed as an argument to the function.
The `if` is a builtin which executes conditionally.