Tíquete #40375

Implement primrec combinator.

: 2020-05-03 03:35 Última Atualização: 2020-05-06 07:55

Relator:
(Anônimo)
Dono:
Estado:
Fechado
Componente:
Prioridade:
6
Gravidade:
3
Resolução:
Fixed
Arquivo:
Nenhum

Details

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.

Ticket History (3/4 Histories)

2020-05-03 03:35 Updated by: None
  • New Ticket "primrec troubles" created
2020-05-03 03:56 Updated by: sforman
  • Prioridade Update from 1 - Lowest to 6
  • Tipo Update from Bugs to Feature Requests
  • Marco Update from (Nenhum) to v0.4.0 (fechado)
  • Dono Update from (Nenhum) to sforman
  • Componente Update from (Nenhum) to Library
  • Summary Updated
Comentário

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!

2020-05-06 07:26 Updated by: sforman
Comentário

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.

2020-05-06 07:54 Updated by: sforman
  • Estado Update from Aberto to Fechado
  • Resolução Update from Nenhum to Fixed
Comentário
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

Attachment File List

No attachments

Editar

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login