Strand notation, I call multi adverb, allows for an infinite parameter list to 
an adverb.  One of the simplest double adverbs is:

 - + 1 : 'u @'
+@-

adverb returns an adverb.  This loses flexbility compared to a conjunction, 
because a conjunction is able to partially bind the - (2nd) parameter in the 
multiadverb, while more complex tricks are needed to partially bind the - to 
the multiadverb first.

A Fork is a function with 3 parameters.  One way to implement that would be a 
conjunction that returns an adverb

% +/ 2 : '(u`)(`v)(`:6)' #

+/ % #

The disadvantage here is that the 3rd % middle fork parameter cannot be bound 
prior to other 2.

With the templating engine, there is considerable flexibility.  Defining a fork 
function F

F =: jt '4: 3: 2:'

+/ % # F Jxp

+/ % #

but also allows partial binding of any parameters to the fork function

% ('+/ ` ` #' bb F Jxp)

+/ % #


So it is about having an easy way to define/use multiparameter modifiers.  
Including easy partial currying.  It lives within J's parsing rules/limitations 
(so far).  The main limitation is that an adverb that returns an adverb 
multiple times does not compose easily with other adverbs, but the workaround 
to combine F and JxP into a single expression (shown by parenthesizing it, but 
if it works parenthesized it can also be named)

ML_z_ =: 0
ncA =: 1 : 'if. 3 ~: 4!:0 < ''u'' do. if. m ismodstring do. m ; ncS m else. 0 
;~ ''('', m lrA ,'')'' end. else. 3;~ ''('', u lrA ,'')'' end.'

ismodstring =:1 : 'if. 0 = 4!:0 <''u'' do. try. q =. m eval catch. 0 return. 
end. 1 2 e.~ 4!:0 <''q''else. 0 end. '

aatrain =: ML daFx NB. perfectly solves the composability of double adverbs. 
But fails if modifier params included.

if. 0 -.@-: 1{:: a =. v ncA do. n =. ,: a end.

if. 1 = 1 {:: (;: inv {."1 a =.(u ncA , n)) ncA do. a aatrain else.

(;: inv {."1 a) eval end.

)


   % '+/ ` ` #' bb('F Jxp' aatrain)

+/ % #

% '+/ ` ` #' (bb 'F Jxp' aatrain)

+/ % #


On Friday, September 11, 2020, 10:59:49 a.m. EDT, Raul Miller 
<[email protected]> wrote: 


Some example uses would be helpful, here.

Is this for taking advantage of the "long adverbial left scope" (which
can accept a fixed length chain of verbs or nouns) and "long
conjunctive right scope" (which can accept a verb and a fixed length
chain of nouns) mechanisms offered by the parser? Or is it for
decomposing arguments structured in some other fashion?

Thanks,

-- 
Raul


On Fri, Sep 11, 2020 at 9:09 AM 'Pascal Jasmin' via Programming
<[email protected]> wrote:
>
> Its an easier way to write functions that include multiple parameters, 
> modifiers as parameters, lets you bind/curry any combination of those 
> parameters, and provides easy autoquoting of a parameter in chosen 
> circumstances.  It behaves like extra u v x y parameters with multiple 
> substitutions of each token, though for that exact behaviour parentheses 
> around either the data-parameter or the token-variable need to be included.  
> WIthout parentheses, the templating engine can insert any string into the 
> template, and so fragment combinations of linear expressions is possible.
>
> A walkthrough of some of the functions
>
> bb =: 1 : 'dltb each (''`''&cut) m'
>
> used to cut linear representations on ` .  This is a helper function that 
> simplifies parameter building.  Similar to traditional language function call 
> that cuts parameters on ",".  ` is used because there are better gerund 
> builder functions for J, and so ` is non essential.  Templates discard the 2: 
> to 9: and _2: to _9: verbs from use, as they too are non essential, and 
> happen to not appear in the addon library.
>
> ' `% `# ' bb
>
> ┌┬─┬─┐
>
> ││%│#│
>
> └┴─┴─┘
>
> builds 3 parameters.  A null parameter passed to template leaves its 
> corresponding token unbound.  It is also possible to pass a verb or noun 
> directly to template that will just bind the first (lowest magnitude) 
> parameter.
>
> NoteV_z_ =: 1 : '(0 (0 :)) label_. 0 (m :)'
>
> Allows embedding documentation in an explicit function.  Adverb where m is 
> the left parameter to :  .  Can be enhanced to provide side effect 
> database/dictionary/queryable function documentation.
>
> jt is the templating engine conjunction.  Its documentation string:
>
> 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. Therefore 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.
>
>
> The Jxp function turns a string into an explicit or tacit expression based on 
> its content.  It also is in embedded documentation format.
>
>
> One of the practical applications of this templating engine is 
> creating/enabling "modifier trains" that mix conjunctions and adverbs.  
> Examples of how those modifier trains should bind parameters is provided, but 
> it is easy to create alternatives.  A next step is a function that takes a 
> series of adverbs and conjunctions, that autobuilds a train of CC CA AC 
> combinators based on the parameter types.
>
>
>
>
> On Friday, September 11, 2020, 05:45:43 a.m. EDT, R.E. Boss 
> <[email protected]> wrote:
>
>
>
>
>
> Am I the only one who don't understand a word of this high-browed J?
> Even not why I should make an effort to digest it.
>
>
> R.E. Boss
>
>
> -----Original Message-----
> From: Programming <[email protected]> On Behalf Of 
> 'Pascal Jasmin' via Programming
> Sent: vrijdag 11 september 2020 05:42
> To: Programming forum <[email protected]>
> Subject: [Jprogramming] A templating framework for J expressions
>
> 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

>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
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