forgot to mention that arguments to strand notation are verb phrases, and each 
verb is responsible for putting its result in a compatible shaped item within 
the list, usually done through boxing

  
   9: -:each +:each *:each altMs 3 4 ;2 4 ;5 6; 7┌─────┬───┬─────┬───┐ 
│1.5 2│4 8│25 36│3.5│ 
└─────┴───┴─────┴───┘ 




----- Original Message -----
From: 'Pascal Jasmin' via Programming <[email protected]>
To: Programming Forum <[email protected]>
Cc: 
Sent: Saturday, August 8, 2015 8:12 PM
Subject: [Jprogramming] a trick for monadic gerund  and /

-`+/ will insert alternating - then + between items of argument.  Those are 
dyadic verbs, and they have to be.

Still the idea of applying monads to alternating items in a list must have 
occurred to others too.  One technique is:

  ('+:';'-:') apply each 4 2 
┌─┬─┐ 
│8│1│ 
└─┴─┘ 

but this doesn't have the auto expansion that gerunds and / have.  A solution

(] ,~ -:@:[)`(] ,~ +:@:[)/ 3 4 2 0 
1.5 8 1 0 


where the trailing 0 is a pad that doesn't get processed.

With my version of strand notation and double adverbs at 
http://www.jsoftware.com/jwiki/PascalJasmin/functional%20algebra%20and%20double%20adverbs%20part%202

This can be made into a clean adverb that adds its own pad, and then removes 
the pad after processing. (needs many definitions from that page).  all one 
line.

altMs =: 'lrT  (''[: }: [:''&,)@:(,&''/ {:,~]'')@:(''`''&joinstring)@:(([: ''(] 
,~''&, ,&''@:[)'' )each) @:( {."1) v2a eval' aatrain 

  9: -: +: altMs  NB. 9: closes strand input
[: }: [: (] ,~ -:@:[)`(] ,~ +:@:[)`:3 {: ,~ ] 


  9: -: +: altMs 3 4 5 6  NB. verbs get inserted left to right
1.5 8 2.5 12 


  9: -: +: *: altMs 3 4 5 6 7 
1.5 8 25 3 14 


  9: *: (-: +: altMs) NB. expression in brackets is assignable adverb
[: }: [: (] ,~ *:@:[)`(] ,~ -:@:[)`(] ,~ +:@:[)`:3 {: ,~ ]
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to