Ticket #39867

Factorial recursion error

Eröffnet am: 2019-12-25 15:33 Letztes Update: 2020-04-29 03:08

Auswertung:
(Anonym)
Verantwortlicher:
Typ:
Status:
Geschlossen
Komponente:
Meilenstein:
Priorität:
2
Schweregrad:
1 - Unterste
Lösung:
Works For Me
Datei:
Keine

Details

I am following along with http://www.kevinalbrecht.com/code/joy-mirror/j00ovr.html the tutorial.

I am trying to calculate the recursive factorial of a number, however I encounter the following error.

joy? 5 1 * primrec

. 5 1 * primrec
5 . 1 * primrec
5 1 . * primrec
5 1 * . primrec 5 1 * . i genrec
5 1 * i . genrec
5 1 [5 [1 * i genrec] i] . ifte

[5 [1 * i genrec] i] 1 [] 5 . infra first choice i


Traceback (most recent call last):

File "/usr/local/lib/python2.7/site-packages/joy/joy.py", line 110, in repl
stack, _, dictionary = run(text, stack, dictionary, viewer.viewer)
File "/usr/local/lib/python2.7/site-packages/joy/joy.py", line 88, in run
return joy(stack, expression, dictionary, viewer)
File "/usr/local/lib/python2.7/site-packages/joy/joy.py", line 75, in joy
stack, expression, dictionary = term(stack, expression, dictionary)
File "/usr/local/lib/python2.7/site-packages/joy/library.py", line 929, in infra
return aggregate, pushback(quote, (stack, (S_swaack, expression))), dictionary
File "/usr/local/lib/python2.7/site-packages/joy/utils/stack.py", line 156, in pushback
return (quote0, pushback(quote1, expression)) if quote else expression

TypeError: 'int' object has no attribute 'getitem' What differences are there in Thun to the Joy described in that tutorial, and does there exist some documentation of the differences?

Ticket-Verlauf (3/5 Historien)

2019-12-25 15:33 Aktualisiert von: None
  • New Ticket "Factorial recursion error" created
2019-12-31 15:00 Aktualisiert von: sforman
Kommentar

Hey! Thanks for the bug report. I'll take a look tonight and get back to you.

2020-04-24 12:03 Aktualisiert von: sforman
  • Schweregrad Update from 4 to 1 - Unterste
  • Komponente Update from (Keine) to Library
  • Meilenstein Update from (Keine) to v0.3.0 (closed)
  • Verantwortlicher Update from (Keine) to sforman
  • Priorität Update from 4 to 2
Kommentar

I got the definition of primrec all wrong, so this example from the original Joy doesn't work at all.

Remove the wrong definition, rename the thing I have (i genrec), and (maybe) implement the OG primrec combinator.

2020-04-29 02:58 Aktualisiert von: sforman
Kommentar

Okay, from the URL above, the primrec operator is described like so:

http://www.kevinalbrecht.com/code/joy-mirror/j00ovr.html

In Joy there is a combinator for primitive recursion which has this pattern built in and thus avoids the need for a definition. The primrec combinator expects two quoted programs in addition to a data parameter. For an integer data parameter it works like this: If the data parameter is zero, then the first quotation has to produce the value to be returned. If the data parameter is positive then the second has to combine the data parameter with the result of applying the function to its predecessor.

So like this I think: ... I made some ASCII art Gentzen diagrams but the tickets system thinks they are spam. :(

Anyhow, the thing to do is pick a different name for i genrec like tail-recur or just tailrec, and maybe implement a primrec combinator.

But the description makes it sound polymorphic, and I'm not at all sure I want that.

It can also be used with data types other than integers.

2020-04-29 03:08 Aktualisiert von: sforman
  • Lösung Update from Keine to Works For Me
  • Status Update from Offen to Geschlossen
Kommentar

https://osdn.net/projects/joypy/scm/hg/Joypy/commits/32029eabc1e8204d727aff2976837ce6d29c7ba4

Rename primrec to tailrec.

This is most of it done. I'm going to close the ticket and worry about implementing primrec later.

Dateianhangliste

Keine Anhänge

Bearbeiten

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