Pascal wrote: >the above is not a useless pattern, but it would still be nice to have a real short circuit.
>the pattern: doN^:testN...@:do2^:test2@:do1^:test1 >might be implementable using clever `:3, and ^:`@: but its not >straightforawd to This is one way (using verbalized adverbs and conjunctions [1,2]): train=. (evoke&6) :. (tie&'') ( shortcircuit=.train o ((power&.:train ~)`(at&.:train ~)/) o |.) v0`t0`v1`t1`v2`t2 v0^:t0@:v1^:t1@:v2^:t2 ShortCircuit=. shortcircuit sv [: v0 t0 v1 t1 v2 t2 v3 t3 v4 t4 ShortCircuit v0^:t0@:v1^:t1@:v2^:t2@:v3^:t3@:v4^:t4 (Stay tuned for the release...) [1] Tacit recursion without $: http://www.jsoftware.com/pipermail/programming/2014-March/035662.html [2] Tacit recursion without $: http://www.jsoftware.com/pipermail/programming/2014-March/035662.html On Tue, Mar 4, 2014 at 9:51 PM, Pascal Jasmin <godspiral2...@yahoo.ca>wrote: > code at bottom of message, > > G2train is needed to make "formal trains" even though `:6 can sometimes > evaluate a list of boxed verbs as a train, if we add conjunctions to the > train, it needs to be formalized as a group of verbs. > > ( '^:'(4<]) addconj"1 0 G2train <"1 ]`+vvtie"1 0]2 4) train6"0 0] 5 4 > 7 4 > ( '^:'(4<]) addconj"1 0 G2train <"1 ]`+vvtie"1 0]2 4) train6"1 0] 5 4 > 11 4 > > (+jointrains '^:'(4<]) addconj"1 0 G2train <"1 ]`+vvtie"1 0]2 4) > train6"1 0] 5 4 2 1 > 16 8 4 2 > > > (+jointrains '^:'(4<]) addconj"1 0 G2train <"1 ]`+vvtie"1 0]2 4)`:6 > (] + 2"_)^:(4 < ]) + (] + 4"_)^:(4 < ]) > > > > addconjar can add tests to each train. > (+jointrains (4<])`(2<]) '^:' addconjar"0 G2train <"1 ]`+vvtie"1 0]2 > 4) train6"1 0] 5 4 3 1 > 16 12 10 2 > > seems a useful way to build and chain a series of power conjunctions > > (composetrains (7<])`(2<]) '^:' addconjar"0 G2train <"1 ]`+vvtie"1 0]2 > 4) train6"1 0] 5 4 3 1 > 11 10 7 1 > > but doesn't quite work the same as a real short circuit: > > (composetrains (9<])`(12<])`(2<]) '^:' addconjar"0 G2train <"1 > ]`+vvtie"1 0] 5+i.3) train6"1 0] 10 4 3 1 > 28 16 15 1 > > here the 3 input fails the >12 test, but still evaluates and passes the > (3+7)> 9 test. > > (composetrains (9<])`(12<])`(2<]) '^:' addconjar"0 G2train <"1 > ]`+vvtie"1 0] 5+i.3) `:6 > [: (] + 5"_)^:(9 < ]) [: (] + 6"_)^:(12 < ]) (] + 7"_)^:(2 < ]) > > note that the tests can also be buit by parameters (and doesn't need the > G2train processing to pass the `:6 parser.: > > (composetrains ( <"1 ]`> vvtie"1 0]9 12 2) '^:' addconjar"0 G2train <"1 > ]`+vvtie"1 0] 5+i.3) `:6 > [:^:((] + 5"_) (] > 9"_)) [:^:((] + 6"_) (] > 12"_))^:((] + 7"_) (] > 2"_)) > > the above is not a useless pattern, but it would still be nice to have a > real short circuit. > > the pattern: doN^:testN...@:do2^:test2@:do1^:test1 > > might be implementable using clever `:3, and ^:`@: but its not > straightforawd to tie two conjunctions (^:`@: is error). I'm not sure that > would work, but there is a simpler approach anyway. Rewrite addconj as a > verb where y is a pair of gerunds corresponding to left and right > conjunction arguments, then join pairs of do, test with ^:, and resulting > pairs with @:. maybe next post. > > the code: > > Cloak1=: (0:`)(,^:) NB. Conjunction to cloak adverbs and conjunctions as > verbs > Cloak=: (5!:1@<'Cloak1')Cloak1 NB. Cloaking Cloak > vtie =: 2 : 'try. ((u"_)`(v"_)"_)^:(0=L.) (u`v) catch. try. u`(v"_) catch. > (u"_)`(v"_) end. end.' > vvtie =: Cloak <'vtie' > train6 =: 4 : ' x `:6 y' > > > jointrains=: 1 : '( [ , (u`'''') ,])/' > composetrains =: [:`'' , {:,~[: jointrains@:}: > ar =: 1 : '5!:1 <''u''' > G2train =: 3 : '; y `:6(`'''')' each > addconj =: 1 : (':';' <(,x);<y ; u ar')("1 0) > addconj2 =: 1 : (':';' <(,u);<y ; x ar') > addconjar =: 1 : (':';' <(,u);<y ; x') > > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm