>  Dyalog APL allows f <- where f is a dyadic function, as in
>  How do I do this in J?

You need to roll up all repeated elements, then do the amendment.  In this 
case, you need to sum all the contributions at the same index, then use the nub 
of the indices to amend the sums back into the array.

           a             =:  10$0
           
           destinations  =:  2 2 5 6 2
           contributions =:  3 4 5 6 7
           
           a             =:  (destinations +//. contributions) 
(~.destinations)} a
           
           a
        0 0 14 0 0 5 6 0 0 0
   
The adverb  /.  is a general tool to roll up repeats.  Its verb argument will 
depend on the function  f  and will normally be  f/  .  In this case,  f  was  
+  and "roll up" meant sum, so the argument to  /.  was  +/  resulting in  +//. 
 .

Amend isn't used as much in J as it is in APL (in my experience).

-Dan

PS:  Dyalog only permits this for certain  f  .  J generalizes this to any 
function, using the method described above.
PPS:  If you know APL, I could use your help fleshing out the APL examples at 
Rosetta Code.  To review the examples I've already submitted, check out  
http://rosettacode.org/wiki/Category:APL  .  To see tasks that would benefit 
from APL solutions, see  http://rosettacode.org/wiki/Category:Programming_Tasks 
 .
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to