>     (2*[)/\ 2 3 4
> 2 4 4

Prefixes:

<\ 2 3 4
┌─┬───┬─────┐
│2│2 3│2 3 4│
└─┴───┴─────┘

Applying a function on these prefixes like you did gives:

(2*[)/ 2
2

Here there is no left argument so it uses the unit element of '*', which is 1.


(2*[)/ 2 3
4
(2*[)/ 2 3 4
4

Explanation of the result of the last prefix array:

f=.2*[

f/ 2 3 4 <===>

2 f 3 f 4

2 f (3 f 4)

2 f 6

4

If you really want the desired result this way, then use e.g.:

inc2=. 2+]

note the difference with your (2+[)


4 inc2/\@:$ 2
2 4 6 8

but I would not do that, instead I would use:

4 +/\@:$ 2
2 4 6 8


But this is focused on the result and not on the concept of recursion.



-- 
Met vriendelijke groet,
=@@i

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to