#funktal — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #funktal, aggregated by home.social.
-
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.
-
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.
-
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 -
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 -
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:
-
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 as6 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. -
Currently, there is no type checking. It's all very bare bones, an awful lot is still missing. There isn't even a compiler executable yet. But I think progress should be a bit faster now. #Funktal
-
The second example shows the use of an algebraic data type, a tuple:
types {
Tup = Int Int MkTup
}main {
6 7 MkTup (\ Int <- (x y MkTup): Tup . x y * )
print
}MkTup creates a tuple of two integers. In Haskell this would be
data Tup = MkTup Int Int
The lambda function pattern matches on the type, so x and y bind to the stored values.
-
Finally, my #Funktal compiler can emit correct #Uxntal for some simple examples.
The first one shows named functions, lambda functions and primitive types:
functions {
sq = (\Int <- x:Int. x x *)
}main {
6 7 (\ Int <- x:Int <- y:Int . x y * sq )
print
}Funktal uses postfix notation for expressions and types. In Haskell, the sq function would be
sq :: Int -> Int
sq = \x -> x*x -
The problem with #Funktal, my functional language for #Uxn, is that very likely, nobody will want to use it because it lacks features. You know how this goes: if I release it bare-bones, a few people try it, they will be put off because of the lack of what they consider essential features, and that's it, as you have only ever one chance.
-
I am still doggedly plugging away at #Funktal, my statically typed functional language for #Uxn. It turns out to be one of the more complex bits of code I've worked on. One reason is that I am coding it in a very old style: the only type of datastructure I use is a fixed-size array of 1-byte or 2-byte integers.