Improved this utility to allow embedding multiple calls to dX in the same expression
code is at https://github.com/Pascal-J/dX-console-dissect/blob/master/dX.ijs the readme file has walkthroughs. ----- Original Message ----- From: 'Pascal Jasmin' via Programming <[email protected]> To: Programming Forum <[email protected]> Cc: Sent: Wednesday, August 12, 2015 5:43 PM Subject: [Jprogramming] a (slight lie) one line version of dissect No idea whether to post on old or new wiki. This utility shows all of the intermediate results (of verb phrases) in a tacit verb. It uses my strand/multiadverb notation under the hood, and so the verb 9: is reserved. This should probably work in J6 and J7 too. (not counting utilites). everything one line except lrT aatrain evaleach pD_z_ =: 1!:2&2 lrA_z_ =: 1 : '5!:5 < ''u''' eval_z_ =: 1 : ' a: 1 : m' lrX =: 1 : ('''('', u lrA , '') '' , lr y';':';'''('', (lr x) , '') ('' , u lrA , '') '' , lr y') evaly =: 3 : 'y eval lrA' NB. removes 1 level of parens from lrT boxes lvProcsRestT =: (1 : '( 0 {:: {: m) eval }: m') AmbiD =: 1 : 'u [ '' '' pD@, u lrX' strbracket =: (0&{@:[ , ] , 1&{@:[) 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. ' ncS=:3 :'z=.y 1 :y label_. 4!:0 <''z'' ' :: _2: NB. nameclass of string 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.' daF =: 1 : ('a =. (''2 : '', (quote m) , '' u'') label_. 1 : (''u 1 :'' , quote a)') daFx =: (0 : ) 1 : ('a =. (''2 : ('', (lr m) , '') u'') label_. 1 : (''u 1 :'' , quote a)') NB. explicit. call with 0 left arg forkorder=:($:@(2&}.) , {. , <)`(2&}. , {. , <)@.(3 = #)^:(1 ~: #) trainorder=: forkorder`($:@(1&}.) , <)@.(0 = 2 | #) lrT =: 0 daFx if. 0 -.@-: 1{:: a =. v ncA do. n =. ,: a end. if. '9:' -: u lrA do. n else. (u ncA , n) lrT end. ) aatrain =: 0 daFx NB. perfectly solves the composability of double adverbs 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. ) evaleach =: 1 : 0 for_i. m do. pD^:(i_index < <:#m) (i eval) :: ((i eval)@:]) y end. : for_i. m do. pD^:(i_index < <:#m) x (i eval) :: ((i eval)@:]) y end. ) strandT =: ([: ,&' AmbiD'@:('()'&strbracket)@:evaly@:; L:1 [: >@{.L:1 [: (#~ (<1) ~: (0-:1&{::)L:1) trainorder@:(<"_1)) 'lrT lvProcsRestT evaleach' aatrain dX =: lrA 1 : '(''9: '', m , '' strandT'') eval' the display is offset (doesn't show up in email) to ease copying it to markdown and lower clutter. Note that dX does not tunnel into "subtrains" 4 5 6 (([: |: ,:) #~ 1 < -:@])dX 1 2 3 (4 5 6) (-:@]) 1 2 3 0.5 1 1.5 (4 5 6) (1 < -:@]) 1 2 3 0 0 1 (4 5 6) ([: |: ,:) 1 2 3 4 1 5 2 6 3 (4 5 6) (([: |: ,:) #~ 1 < -:@]) 1 2 3 6 3 but you can go directly to a subtrain line of interest and add dX to it and enter twice to get the display. Result of dX is same as fork result so you can extend it to the left using its result. (also the last expression display is also the origninal command, so you can just use that line to edit/repeat) +: (4 5 6) ([: |: ,:)dX 1 2 3 (4 5 6) (,:) 1 2 3 4 5 6 1 2 3 (4 5 6) ([:) 1 2 3 (4 5 6) ([:) 1 2 3 (4 5 6) ([: |: ,:) 1 2 3 8 2 10 4 12 6 though, if you want the display, you can extend it within the fork (4 5 6) ([: +: [: |: ,:)dX 1 2 3 (4 5 6) (,:) 1 2 3 4 5 6 1 2 3 (4 5 6) ([:) 1 2 3 (4 5 6) ([:) 1 2 3 (4 5 6) ([: |: ,:) 1 2 3 4 1 5 2 6 3 (4 5 6) ([:) 1 2 3 (4 5 6) ([:) 1 2 3 (4 5 6) ([: +: [: |: ,:) 1 2 3 8 2 10 4 12 6 tiny flakiness when [: is in train NB. dyadic hooks will show weird intermediate results, but hopefully not crash (use forks :P) (#~ 1 < -:)dX 1 2 3 >>> (1 < -:) 1 2 3 0 0 1 >>> (#~ (1 < -:)) 1 2 3 3 4 5 6 (#~ 1 < -:)dX 1 2 3 >>> (4 5 6) (1 < -:) 1 2 3 0 >>> (4 5 6) (#~ (1 < -:)) 1 2 3 6 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
