Martin Kreuzer wrote: > Hi all - > > While doing a little piece on computing Fibonacci numbers and the > Golden ratio, I came across this behaviour of recursive functions > which I do not yet understand: > > r:=. 2 + i.7 > fac=: 3 : 'if. y <: 1 do. 1 else. y * fac y - 1 end.'
r,.fac"0 r 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320 You have to make fac have rank 0 if you want it to behave like sin. The weird behavior comes from r<:1 0 0 0 0 0 0 0 which tests false and (r-1)<:1 1 0 0 0 0 0 0 which tests true. Best wishes, John ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
