cocurrent 'z' NB. utilities pasted from jpp, hopefully did not forget any:
NoteV_z_ =: 1 : '(0 (0 :)) label_. 0 (m :)' bb =: 1 : 'dltb each (''`''&cut) m' lrA =: 1 : '5!:5 < ''u''' eval =: 1 : 'if. 2 ~: 3!:0 m do. m else. a: 1 : m end.' numcolonnot01 =: {.@((0 1 _1 -.@e.~ ".@}:) *. ':' = {:)`0:@.('''' = {:) a2blr =: 1 : 'if. 3 = nc <''u'' do. < u lrA else. boxopen m end.' jt =: 2 NoteV template n includes tokens in form of number colon (except for 0: 1:). if n string it is tokenized. those tokens will be replaced with blocked string expressions in m a repeated token gets replaced multiple times. a negative token gets replaced by the quoted m block. m blocks will replace right to left in order of sorted token absolute values (ie. if tokens are 2: _3: 5:, leftmost of 3 m blocks will replace 5: Rightmost will replace 2:) a null('') m block skips the token binding. Replaces token with +100 magnitude. Limit of 100 unique replacement tokens. too short of an m list, just partially binds the lowest magnitude token values. an unboxed u (verb) parameter is replaced with a single boxed lr. unboxed m is boxed. Less efficient to pass one parameter at a time, but supported. if not fully bound, returns (jt n) adverb with n partially bound tokens. if fully bound, returns result string multiline n can be coerced into ` delimited single line to fit this function. ) n =. ;:^:(0 = L.) n m =. |. u a2blr Ilist =. I. {.@numcolonnot01 &> n nlist =. ".@}: each Ilist { n NB. numeric version of each n: param. 'too many parameters given' assert (#m) <: # ~. | each nlist snlist =. /:@:( (| , ]) each) nlist r =. m #~ (#m) {. #/.~ snlist { | each nlist a =.|: jthelper r ,. (nlist (,<)"0 Ilist) {~ snlist {.~ #r n =. ({. a) (; {: a)} n if. 1 e. numcolonnot01 &> n do. (jt n) else. ;:inv L:1 <^:(1 = L.) n end. ) jthelper =: 3 : 0("1) 'a b c' =. y if. '' -: a do. a =. ':' ,~ ": (* * 100 + |) b elseif. 0 > b do. a=. quote a end. a;c ) Jxp =: cutLF v2a 1 NoteV creates tacit or explicit expression based on m. m is either string (auto boxed to 1) or "multiline equivalent" boxed format. if includes v/n, explicit conjunction if includes u/m, explicit adverb if includes x but not single line :, explicit dyad if includes y, explicit monad else tacit or noun expression, eval'd if not multiline. ) if. 1 = #m do. m =. (>m) bb end. NB. ` is coded multiline m =. ;: each m if. +./ , (;: 'v n') e.S:1 m do. 2 : (;: inv each m) elseif. +./ , (;: 'u m') e.S:1 m do. 1 : (;: inv each m) elseif. (0 = (< ;: ':') e. m) *. +./ (;: 'x') e.S:1 m do. 4 : (;: inv each m) elseif. +./ (;: 'y') e.S:1 m do. 3 : (;: inv each m) elseif. 1 = #m do. (> ;: inv each m) eval else. ;: inv each m end. ) some examples this permits are an easy way to create conjunction trains: CC =: 2 : '( u ; v ) jt ''u (4: 3:) (2: v)'' Jxp' CA =: 2 : '( u ; v ) jt ''(u 3: v) 2:'' Jxp' AC =: 2 : '( u ; v ) jt ''(u 3:) 2: v'' Jxp' CC is a conjunction that returns an adverb that returns a conjunction (3/5 parameters total) +: +'@' CC '@:'- NB. binding order same as if it were called in multi adverb form. +@+:@:- The same function can be done with more flexible bindings as a 5 parameter adverb: ' `+:` `@` ' bb jt '5: (4: 3:) (2: 6:)' Jxp (jt(;:'+:(104:@)(102:106:)'))Jxp '+`-` @:' bb ' `+:` `@` ' bb jt '5: (4: 3:) (2: 6:)' Jxp -@+:@:+ Both the CC and 5-adverb version are much easier to write and read than the nested quote monstrocity that is the alternative. Jxp is a suggestion I believe Henry made on wiki. At first, I didn't like it because the intent of a function is both usefully described, and an early intentional decision. But it is convenient when that initial intent can change: '+`-` @:' bb ' `+:` `@` ' bb jt '5: (4: 3:) (2: 6:) y' Jxp '@`@:' bb jt '+ _3: CC _2:' Jxp NB. negative token markers get quoted before replacement. 2 : 'u ( + @ ) ( @: v )' ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm