Email or username:

Password:

Forgot your password?
WimⓂ️

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.

13 comments
Devine Lu Linvega

@wim_v12e Oh, that is cool. Could you make me a rom of this one? I'd love to run it through beetbug

WimⓂ️

@neauoire I need to log off now, I will upload one tomorrow. Do you need only the .rom or also .rom.sym?

Devine Lu Linvega

@wim_v12e you're using deep stacks to do this, it might overflow for more recursions:

WimⓂ️

@neauoire I know, it is not a tail recursion. The fixedpoint function is elegant but not efficient. It is important that Funktal can handle it, and in fact it showed me a design flaw I still have to fix. But in practice I would not use it.
I'll send you a tail-recursive one for contrast later. Your tool is very cool!

Devine Lu Linvega

@wim_v12e ah! okay :) The tool is this one, if you ever wanna step through a rom
git.sr.ht/~rabbits/beetbug

WimⓂ️

@neauoire I think I was wrong yesterday, I think it is the way I wrote the iteration, not the fixedpoint function, that results in it not being tail recursive. When I get it debugged I'll have a look with beetbug. Does it have breakpoints?

WimⓂ️ replied to Devine Lu Linvega

@neauoire Great! In the meanwhile, I've pushed the .tal, .rom and .rom.sys for a tail-recursive factorial, the files are fact.*

codeberg.org/wimvanderbauwhede

Devine Lu Linvega replied to WimⓂ️

@wim_v12e Thanks! I'll take them for a spin. Let me know if you have issues with beetbug.

WimⓂ️ replied to Devine Lu Linvega

@neauoire I will, thanks. But first I think I have some particularly hairy debugging to do.

Go Up