>simplicity. Simplicity is a virtue?


On designing econometric models one of the best advised: "Keep it
Sophisticatedly Simple."  I think his advice also applies to programming;
actually that is the primary reason why I prefer J versus other
conventional programming languages and even to APL (at least the decade old
versions of APL that I used to know).  Moreover, writing only tacitly keeps
the list of concepts simple  in my mind.



To stress the main point of my initial message; the case I am making for
recursion without $: is, for instance,  the fixed tacit (or otherwise)
implementation of the adverb sna.  The (atomic representation of the)
Recursion adverb is an interesting testing argument taken by sna.
Nevertheless,
I posed the implementation of Recursion as a puzzle and yours and any other
variants are very welcome.



   Recursion=:1 :0

   '`if else test next'=. m

   [: (if else^:(-.@test))/f. (, next@{:)^:(test@{:)^:_ f.

)



   fact=. *`1:`*`<: Recursion



   fact 5

120



So far so good.  Unfortunately,



   fact 0

0



Also,



   Fib=. >&1`(i.@>:)`(] , +/@(_2&{.)@])`<: Recursion



   Fib 7

|domain error: Fib

|       Fib 7

|[-15]



Can you fix your interesting (primitive recursive) version?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to