Have a look at the diagrams for Hook and Fork in

http://www.jsoftware.com/docs/help801/dictionary/dictf.htm

--Kip Murray

Sent from my iPad

> On Mar 18, 2014, at 2:15 PM, Pascal Jasmin <[email protected]> wrote:
> 
> to be clear, I am in no way asking for how to double a product.
> 
> what the function is actually equivalent to, though is: (*+*)  
> 
> What seems interesting about the function is it is doing something I 
> previously thought was impossible.  Saving and reusing intermediate (noun) 
> results in a tacit function.  
> 
> It behaves as expected, though I am only concerned about not hitting domain 
> errors, and that the intermediate assignment is picked up when trying to 
> retrieve it.  The expression is meant to be as simple as possible other than 
> the title's feature.
> 
> 
> 
> ----- Original Message -----
> From: Raul Miller <[email protected]>
> To: Programming forum <[email protected]>
> Cc: 
> Sent: Tuesday, March 18, 2014 2:37:26 PM
> Subject: Re: [Jprogramming] intermediate tacit result assignments
> 
> Here's another function which achieves that end:
> 
> test9=: 2 * *
> 
> One interesting thing though, when comparing different expressions which
> accomplish the same end, has to do with how their components can be used
> differently.
> 
> And there's something to be said for having a wide variety of components.
> (Not all of those things to be said are good things, though some are.)
> 
> But consider, for example:
> 
>    1 2 3 (4 : 'c' + 4 : 'c =: x * y')"2 p:i.3 3
>   4   6  10
> 28  44  52
> 102 114 138
>    c
> 2  3  5
> 14 22 26
> 51 57 69
>    1 2 3 (4 : 'c' + 4 : 'c =: x * y')"1 p:i.3 3
> 4 12  30
> 14 44  78
> 34 76 138
>    c
> 17 38 69
>    1 2 3 (4 : 'c' + 4 : 'c =: x * y')"0 p:i.3 3
>   4   6  10
> 28  44  52
> 102 114 138
>    c
> 69
> 
> Is that how you expected it to behave?
> 
> (Notice, in particular, how the "off-diagonal" elements for your expression
> at rank 1 are different from those of the same expression at rank 0 and
> rank 2. There's a simple explanation for this, but - like most realizations
> - it's only obvious in retrospect.
> 
> Thanks,
> 
> -- 
> Raul
> 
> 
> 
> 
> On Tue, Mar 18, 2014 at 1:47 PM, Pascal Jasmin <[email protected]>wrote:
> 
>> 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
> ----------------------------------------------------------------------
> 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