Actually, 5 (3 :'C') 13 was that domain error. You did not assign this a name, however, so let's fix that:
First, your definition of f: f=: 4 : 'C =: x * y' NB.f 13 result is domain error Second, let's give 3 :'C' a name: h=: 3 :'C' Now, let's exercise them: 5 f 13 65 5 h 13 |domain error: h 5 (h + f) 13 |domain error: h See? Anyways, a more general issue is that we use words to relay thoughts and we sort of have to hope that they are adequate to convey them. But without a shared context quite often we latch onto different thoughts as the intended meaning. There are all sorts of techniques for managing this kind of thing, and a certain amount of tolerance is essential to wanting to get it right. Thanks, -- Raul On Thu, Mar 20, 2014 at 10:55 AM, Linda Alvord <[email protected]>wrote: > In my example, 13 was not the domain error, rather 5 f 13 was. > > Linda > > -----Original Message----- > From: [email protected] [mailto: > [email protected]] On Behalf Of Pascal Jasmin > Sent: Thursday, March 20, 2014 7:45 AM > To: [email protected] > Subject: Re: [Jprogramming] intermediate tacit result assignments > > f 13 is a domin error bc f is dyadic ( 4 : ...) > > usually the fork ([ f ]) 13 is equivalent to f 13, but the one difference > is that though x[ y is x, ] y(monadic) is y. So ([ f ]) 13 is 13 f 13 > instead of domain error. > > > Be careful as C may be using an earlier value. > > The point of the exercise was to always set that value. Your h function > does not set C. > > A simpler version of the example > > fget =: 4 : 'C' > fset =: 4 : 'C =: x * y' > 2 (fget + fset) 3 > 12 > > > ----- Original Message ----- > From: Linda Alvord <[email protected]> > To: [email protected] > Cc: > Sent: Thursday, March 20, 2014 5:34:16 AM > Subject: Re: [Jprogramming] intermediate tacit result assignments > > Here’s how I studied you example. > > > (3 : 'C' + [ 4 : 'C =: x * y' ] ) 13 > 338 > f=: 4 : 'C =: x * y' > NB.f 13 result is domain error > g=: 4 : 'C =: x * y'] > g 13 > 169 > C > 169 > g=: 4 : 'C =: (A=:x) * y'] > erase 'C' > 1 > g 13 > 169 > C > 169 > A > 13 > (3 : 'C' + [ 4 : 'C =: x * y' ] ) 13 > 338 > h=: 13 : 'C' + [ 4 : 'C =: x * y' ] > erase 'C' > 1 > h 13 > 338 > h > 169"_ + [ 4 : 'C =: x * y' ] > C > 169 > erase 'C' > 1 > 5 (3 : 'C' + [ 4 : 'C =: x * y' ] ) 13 > |domain error > | 5 (3 :'C'+[4 :'C =: x * y'])13 > |[-18] > C > 65 > > Be careful as C may be using an earlier value. > > Linda > > > -----Original Message----- > From: [email protected] [mailto: > [email protected]] On Behalf Of km > Sent: Tuesday, March 18, 2014 5:53 PM > To: [email protected] > Subject: Re: [Jprogramming] intermediate tacit result assignments > > 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 > ---------------------------------------------------------------------- > 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
