On Mon, Aug 25, 2014 at 9:51 PM, Raul Miller <[email protected]> wrote:
> http://www.integralist.co.uk/posts/understanding-recursion-in-functional-javascript-programming/#the-solution
> looks like it is describing this:
>
> trampoline=:3 :0
> try.
> while. 1 do.
> y=. y`:6''
> end.
> catch.
> y
> end.
> )
>
The linked url includes a sum function that is applied against the
trampoline. How would that be done in J? I tried some things and could
not figure out how to bind the x/y to the gerund, which is what I
assumed I needed to do
Don't run this code as it will crash J
trampoline=:3 :0
try.
while. 1 do.
y=. y`:6''
end.
catch.
y
end.
)
NB. warning, crashes J
recur=: 4 : 0
if. y > 0
do. trampoline recur&(y+1)`''
else. x
end.
)
sum=: 4 : 0
trampoline (x recur y)
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm