NB. === Distribute Operators Over Gerunds === NB. Given the formal name of a primitive modifier (adverb NB. or conjunction), doog will derive an operator of the NB. same class. The derived operator is related to the one NB. named, except that it is extended to gerunds. NB. NB. Much in the same way that rank abstracts the operation NB. of verbs on nouns, so doog abstracts the operation of NB. modifiers on verbs. Both rank and doog modify their NB. argument such that the derived entity properly handles NB. arrays of arguments. NB. NB. Howerver, whereas arrays of nouns are just nouns, arrays NB. of verbs are gerunds. Therefore doog extends primitive NB. modifiers (such as @), to operate on gerunds. The NB. arguments to a doog-derived modifier may be gerunds, and NB. the result is always a gerund. NB. NB. In the case that that the arguments to a doog-derived NB. modifier are not gerunds, then the modifier acts just NB. like its named counterpart (except that it produces a NB. gerund; the atomic representation of the result of its NB. counterpart). NB. NB. Otherwise, doog applies the modifier to or between each NB. verb or pair of corresponding verbs in the in the NB. gerund(s). In the case of a derived conj with only one NB. gerundal argument, the other argument may be a verb or NB. a noun, with the expected results. NB. NB. Gerunds are distinguised from other nouns in that each NB. of their atoms is a valid atomic representation. doog =: adverb define M =. a: 1 : m cm =. conjunction = ncM =. nc {. ;: 'M' lrep =. '''(m ,&<~ 5!:1{.;:''''m'''') {::~ *./ 3 : (''''y 5!:0'''';''''1'''') :: 0:"0 m'';''{. u`[''' prmb =. , ' 1 : (((noun,verb) i. nc{.;:''' , ')',~ lrep ,~ ''' ) {:: ' ,~ ] ncM : ( ( cm# 'u =.' ,prmb 'u' ) ; ((, ' =.' , prmb) uv) ; (cm#'u'), ' ((,' ,(5!:5{.;:'m') , ')' , '<@; <)@,"0 ' , uv =. cm{'uv') ) NB. This adverb emulates the undocumented, NB. pre-J601c behavior of compositions with gerund: NB. See Test Block A. At =: '@' doog Atop =: '@:' doog NB. The adverb Across provides a mechanism to apply succesive verbs NB. (a gerund) to a corresponding list of nouns (the gerund will be NB. extended cyclically if required). See Test Block B. First =: Atop {. Across =: First (;.2)~ (`1:) (`:6) Ax =: 1 : 'u Across : (u;._2)' NB. Morever, doog extends this behavior (in two ways). Whereas NB. the J implementation restricted compositions with gerunds to the NB. forms (m@v u@n m@n), (m@:v u@:n m@:n), (m&:v u&:n m&:n), and m&n , NB. doog can distribute any conjunction. In particular, '&.' doog NB. will probably find many uses. See Test Block C. Each =: '&.' doog > AcrossBoxed =: Each Across BxAx =: (< Atop) Across Abx =: Each Ax NB. The second extension doog provides is that it can distribute NB. adverbs as well as conjunctions. See Test Block D. Over =: '/' doog NB. Put it all together for a nice effect: we can now define NB. a dyadic Across (apply successive verbs dyadically between NB. successive item pairs ). See Test Block E. Every =: '&:' doog > AcrossDyad =: Over Every Across ( @:(,&:<"_1) ) NB. Test cases testOnLoad =. 0 NB. 0 disables, 1 enables. 0!:(+:testOnLoad) noun define NB. Block A: Emulate pre-J601c compositions with gerund 1: At 3: -: {. 1:@3:`[ 1:`2: At 3: -: 1:@3:`(2:@3:) 1: At (3:`4:) -: 1:@3:`(1:@4:) 1:`2: At (3:`4:) -: 1:@3:`(2:@4:) NB. Block B: Apply successive verbs to succesive items. ( +:`-:`*:`>: Across i. 4*3 ) -: ,( +:0+a ),.( -: 1+a ),.( *: 2+a ),.( >: 3+a=.4*i.3 ) NB. Block C: Distribute arbitrary conjunctions. ( +:`-:`*:`%: AcrossBoxed (1+i.4) *&.> ./) +/\ 1 + ;len )&$: :(vrb Ax) NB. 1 + for the field delimiters Q =. cocreate '' v__Q =. cocreate '' ('`' , ;:^:_1 vbs , L: 0 '__v__Q') =. dfs tbl__Q =. ,.&:>/ (nam , L: 0 '__Q') =. ctr (]\~ -@# % [: +/ LF&=) y NB. _ , 1 + {: $ y Q NB. Closing Paren --> ) NB. Column spec format is name;type;width columns =. _3 ]\ 'acct';'#';2 ;'sub';'#';3 ; 'name';'"';6 NB. # means numeric, " means string. fw_data =. noun define NB. Fixed width data, columns correspond to above description. 0 0 Dan 1 _1 Henry 2 _2 Oleg 3 _3 Raul 4 _4 Roger 10 _10 Lam 11 _11 Bjorn 12 _12 Tuttle 13 _13 Eric 14 _14 Devon NB. Closing Paren -->) NB. fw_data =. , LF ,.~ (,. ' '&,.)&:>/(<@:> ;: 'Dan Henry Oleg Raul Roger Lam Bjorn Tuttle Eric Devon'),~ ":@:,.&.> (; -), 0 10 +/ i. 5 T =: columns parse fw_data tbl__T 0 0 1 1 _1 2 2 _2 3 3 _3 4 4 _4 5 10 _10 6 11 _11 7 12 _12 8 13 _13 9 14 _14 10 acct__T 0 1 2 3 4 10 11 12 13 14 name__T 1 2 3 4 5 6 7 8 9 10 str__v__T^:_1 name__T +---+-----+----+----+-----+---+-----+------+----+-----+ |Dan|Henry|Oleg|Raul|Roger|Lam|Bjorn|Tuttle|Eric|Devon| +---+-----+----+----+-----+---+-----+------+----+-----+ ) NB. If you're not Dan Bron, ignore these two definitions for now. NB. If you're curious, it's related to the verb parse in the NB. "other uses" section above. Encap =: adverb define 4 : (1 |. 'm[(''__m'',L:0~{.x)=. ({:x) BxAx y';'m =. ',5!:5{.;:'m' ) ) encap =: dyad define x (cocreate '') Encap&|: y )