Implement primrec combinator.
Thanks for opening this ticket! I really appreciate it.
I wasn't sure about implementing primrec only because it seems to be specified as a polymorphic function and I'm kind of trying to avoid that sort of thing. On the other hand I want to stay close to the original Joy as I can.
I'll add a primrec combinator.
The tailrec combinator just implements the common "tail-recursion" pattern. It's different.
Thanks again!
https://osdn.net/projects/joypy/scm/hg/Joypy/commits/005ce04ac54fd136ac1dd1fede2f09039189e5e0
Still need to add docs.
joy? 5 [1] [*] primrec 120 <-top
joy? 5 [1] [*] [primrec] trace 5 [1] [*] . primrec 5 4 [1] [*] . primrec * 5 4 3 [1] [*] . primrec * * 5 4 3 2 [1] [*] . primrec * * * 5 4 3 2 1 [1] [*] . primrec * * * * 5 4 3 2 1 0 [1] [*] . primrec * * * * * 5 4 3 2 1 . 1 * * * * * 5 4 3 2 1 1 . * * * * * 5 4 3 2 1 . * * * * 5 4 3 2 . * * * 5 4 6 . * * 5 24 . * 120 . 120 <-top
It's beautiful.
But the extra 1 * at the and suggests a variation where the base function is responsible for popping the zero (or not) if required.
Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit http://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?- joy(`5 [1] [*] primrec`, [], So), joy_terms_to_string(So, Str). So = [int(120)], Str = "120" . ?-
https://osdn.net/projects/joypy/scm/hg/Joypy/commits/a42357f12ac731ea4db059b867ba45762bc51bbd
I'm a new joy user and trying to follow some essays.
When I use the following program on other joy implementation it works fine: 5 1 * primrec However, it fails in Thun.
I saw that in library.py a method called tailrec is implemented, but it does not behave in the way I had expected.