Closed ghost closed 3 years ago
Erhm... that my friend is called infinite recursion 😬
At present there are no checks, but Nim seem to limit to 2000 or something then throws an exception (in dev mode). I will see if I can trap it...
Erhm... that my friend is called infinite recursion 😬
What is wrong with my code? I don't understand why recursion that it makes.
OK I tried handling the segfault but in this case Nim doesn't really help: I cannot trap anything in case of a stack overflow. I would have to somehow limit recursion but I'd rather not do it... (and it would be quite tricky to do it properly).
What's wrong with your code? Right well, have a look at the docs about linrec. Basically what happens is the following.
You have this:
0 (dup 5 >) (dup puts) () 'succ
So:
You get the picture...
5 (dup 0 ==) 'succ (dup pred) '* linrec
-> 5 4 3 2 1 1 * * * * *
I'm a bit confused about linrec
usage. Could you explain how it works?
Sure... Although for better theory I recommend the Introduction to Joy, and specifically the part about recursive combinators. Joy is the concatenative language that inspired min btw.
So linrec
implements linear recursion and it takes 4 quotations, which can be identified as follows:
So the algorithm goes like this:
It is quite a cool way to generalize linear recursion, just it takes a bit to get used to it. 😊
Sure... Although for better theory I recommend the Introduction to Joy, and specifically the part about recursive combinators. Joy is the concatenative language that inspired min btw.
So
linrec
implements linear recursion and it takes 4 quotations, which can be identified as follows:
- "if-part"
- "then-part"
- "else1-part"
- "else2-part"
So the algorithm goes like this:
if "if-part" returns true
- then "then-part" is executed and the execution ends.
otherwise "else1-part" is executed, then:
- recursion occurs, go back to 1.
- "else2-part" is executed.
It is quite a cool way to generalize linear recursion, just it takes a bit to get used to it. 😊
Oh... i thought which else2-part
as finally
stage that runs after every conditional control:
Evaluates quot1.
If quot1 evaluates to true, then it evaluates quot2.
Otherwises it executes quot3 and recurses using the same four quotations.
**Finally**, it executes quot4.
That was helpful!!
Introduction to Joy
I wonder what differs min from Joy? I looked and didn't see any difference surprisingly. Or... this is a Nim wraption of Joy?
But i wrote so many things with min and i like min more always.
Well, min was inspired by Joy. The syntax is more or less the same, the most notable difference being parenthesis instead of square brackets for quotations. Also most of the operators in the stack modules were implemented based on Joy combinators and other combinator birds.
I was always fascinated by Joy. However, Joy is not practical, it is an academic language prototype to illustrate concatenative programming. Unlike Joy, min:
I understood the differencies, thanks!
Look at #139
0 (dup 5 >) (dup puts) () 'succ linrec
putting this in repl did a sudden exit in repl.I found a NEW(New Exit Way) in min repl. Could you explain why the sudden exit happens?