With some simple modifications, we can generalize to Distributing
Operators Over Gerunds (i.e. we can distribute adverbs in addition to
conjunctions).
doog =: adverb define
M =. a: 1 : m
cm =. conjunction = ncM =. nc {. ;: 'M'
ncM : ( 'v1=.{.^:(1 -: #)@:}:' ; (cm#'(v1 v`[)') , '((,'
,(5!:5{.;:'m') , ')' , '<@; <)@,"0' , (cm#'~') , '(v1 u`])' )
)
Given the formal name of a primitive operator, doog will derive an
operator of the same class. When that derived operator is given
gerundial argument(s), it applies the primitive operator to each (pair
of) verb(s) in the gerund(s), and returns the modified gerund.
Silly example:
+`* '/' doog Across i. 4 10x
45 335221286400 245 2306992893004800
i.e. give the sums of the even rows and the products of the odd rows.
One "real" application that comes to mind is Raul's question in
http://www.jsoftware.com/pipermail/general/2005-March/020791.html .
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm