home.social

#funktal — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #funktal, aggregated by home.social.

  1. 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.

  2. 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.

  3. 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

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

    wimvanderbauwhede.codeberg.pag
    #Funktal
    #Uxn

  5. 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.

    codeberg.org/wimvanderbauwhede
    #Uxn #Funktal

  6. 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

  7. 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

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

    "Funktal: a frugal functional programming language"

    wimvanderbauwhede.codeberg.pag

    You can also try it out:

    codeberg.org/wimvanderbauwhede

    #Funktal #Uxn

  9. 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.

  10. 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.

  11. 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.

  12. 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

  13. 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.

    #Funktal

  14. 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

  15. 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.

  16. 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.