interesting function, Raul, but not quite what I was doing: test8 =: 4 : 'c' + [ 4 : 'c =: x * y' ]
function simply multiplies x and y and then doubles result. Its a 5 element train where the : conjunctions makes single train elements. The point is doing this with potntial side effects and saved intermediate results, which has escaped my previous attempts at such possibilities. Rank modification is relatively easy, though may require parens. perhaps clearer with parens: (4 : 'c') + [ (4 : 'c =: x * y') ] 2 test8 3 12 c 6 2 test8 3 2 1 12 8 4 c 6 4 2 ________________________________ From: Raul Miller <[email protected]> To: Programming forum <[email protected]> Sent: Tuesday, March 18, 2014 1:25:32 PM Subject: Re: [Jprogramming] intermediate tacit result assignments It's not clear to me what you want to accomplish here - no sample data, no results. Also note that while this is, in a sense, tacit, you'll get some ... interesting (and probably unintended) behaviors if you try using your 3 : and/or 4 : verbs with rank. I've got some code I'm working on which uses variables in a tacit expression. Here's an example: mergetable=:2 :0 : tinds=. 1+i.#m ginds=. -1+i.#n tlen=. {:@$x glen=. {:@$y mergecol=. [:`tonly`both`gonly@.(3&#.@:*) tget=. {&x@<:@{.@(#~ 0&<) gget=. {&y@<:@|@{.@(#~ 0&>) tnul=. (tlen#a:)"_ gnul=. (glen#a:)"_ tonly=. tget,gnul gonly=. tnul,gget both=. tget,gget (m,n) mergecol/. tinds,ginds ) Example use: (i. 4 3) (;:'this is a test') mergetable (;:'that is not like this')&:(]each) p:i.5 2 ┌─┬──┬──┬──┬──┐ │0│1 │2 │23│29│ ├─┼──┼──┼──┼──┤ │3│4 │5 │5 │7 │ ├─┼──┼──┼──┼──┤ │6│7 │8 │ │ │ ├─┼──┼──┼──┼──┤ │9│10│11│ │ │ ├─┼──┼──┼──┼──┤ │ │ │ │2 │3 │ ├─┼──┼──┼──┼──┤ │ │ │ │11│13│ ├─┼──┼──┼──┼──┤ │ │ │ │17│19│ └─┴──┴──┴──┴──┘ ~.;:'this is a test that is not like this' ┌────┬──┬─┬────┬────┬───┬────┐ │this│is│a│test│that│not│like│ └────┴──┴─┴────┴────┴───┴────┘ In other words, this addresses the problem of "given two tables with different column headers, build a bigger table with combined headers and all the rows from each table." I put the table on its side (so columns are J items), but the interesting thing, here, is that I am using numeric indices to refer to external data. You'd want to transpose the table to show rows and columns more traditionally. (I'm using boxes here because "in real life" I am working with text rather than numbers.) This particular example allowed me to use (in this case) J's /. adverb without actually asking it to manipulate the data which I am grouping together. (Though in this particular example, I've brought everything together in the final result - this let me use J's error detection features in a way which would not have worked if I had left the data in external, "explicit" contexts.) Thanks, -- Raul On Tue, Mar 18, 2014 at 12:26 PM, Pascal Jasmin <[email protected]>wrote: > Here is a neat way to get intermediate results within a tacit expression. > Many drawbacks, but it is possible. Drawbacks include global variables, > and dyad vs. monad must be known prior to access: > > 3 : 'c' + [ 4 : 'c =: x * y' ] > > That may not look very tacit, but it is :P intermediate result c is > accessed later in the fork. > > the biggest drawback is accessing the result (3 : 'c') If the access is > in a dyadic part of the expression, it needs to be (4 : 'c') > > Any improvements? > ---------------------------------------------------------------------- > 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
