As a newer J learner, I've been meaning to ask something for quite a 
while now, and Raul's response gives me an opportunity.

But first, Raul, I have an imponderable: your solution works for the 
test case, and yet it fails with

|domain error
|       (~...@[,.+&.>//.)/|:t1

for the "real" data, which are structured EXACTLY like the test data, 
only with longer key names and far more rows.  Since I can't attach 
files in the forum, can I email you the actual data file I'm using 
(less than 2800 bytes) so that you might have a better chance to figure 
out what's going on?  One possibility for the problem is that the 
values in the second column are actually literal, not numeric (I 
neglected to note that, sorry)--however, since I don't completely 
understand your code (see below), I'm not sure where/how to make any 
changes to the code that might be needed for that adjustment.

> I hope my explanation is clear enough -- if not, and
> if the relevant dictionary entries do not clear things
> up for you, just ask.

> t1=: col1 ,. ]&.> col2
> t2=: (~...@[ ,. +&.>//.)/ |:t1 

I understand much of what you wrote, but I'm having the darndest time 
understanding the DYADIC use of "[" and "]"--which is my long-standing 
question in mind that I mentioned at the start of this message.

The very lengthy recent discussion in JChat concerning Don Watson's 
desires for what he considered simplification of J's syntax gave me a 
moment of enlightenment about [ and ] .  (On the other hand, maybe you 
all might consider it a moment of *mis*-enlightenment!)  And that "aha" 
moment was that "[" referred to the noun in the left "x position" with 
reference to the entire tacit verb expression and that "]" referred to 
the noun in the right "y position" with reference to the entire verb 
expression--in other words, in "x tacitverbexpression y", any "[" 
within the tacit verb expression refers to the value of x and any "]" 
within the tacit verb expression refers to the value of y.  I don't 
know if this understanding is correct, though.

Now here is where I need further enlightenment: if what I just said is 
true, then the Dictionary definition of "[" and "]" (left and right) 
seems to be wrong as it stands.  (This ties in as well with Raul's t1 
and t2 definitions above.)

Taking the Dictionary definition exactly and literally, it would appear 
that in t1 everything to the left of the "]" should be thrown out and 
only the "]" and its rightward elements would be returned.  In t2 
everything to the right of the "[" (up to the parenthesis) should be 
thrown out and only the "[" and its leftward elements would be 
returned.  Likewise, using the literal definition rather than the 
understanding I noted above, in a tacit expression "a [ b ] c" where a, 
b, and c represent sequences of J primitives, the Dictionary definition 
seems to say to throw out "a [ b", returning only the result of c.  In 
a similar manner, in the tacit expression "a [ ( b ] c)", the 
Dictionary definition seems to say to throw out "(b ] c)"--which yields 
the result of c, returning only the result of a.

Now it's a well-accepted fact within the J community that the 
Dictionary is always absolutely authoritative and can never be wrong.  
I accept that, too.  However, in this case, I also posit the suggestion 
that the Dictionary definition for left and right is TOO terse, leading 
to possible errors of understanding because the definition contains 
neither guidance for nor constraints on what the words "yields", 
"left/right argument", and "x/y" mean or refer to in both explicit and 
tacit usage.  It currently seems that, if it's correct for explicit 
verbs, then it's wrong for tacit verbs; likewise, if it's correct for 
tacit verbs, then it's wrong for explicit verbs.  This can't be right, 
so it's currently a paradox for me.

Because of all this, I need help with "[" and "]"--for me, these are 
one of the most confusing aspects for a beginner to understand in terms 
of attempting to read J code because, using the Dictionary definition, 
they (or, rather, the code they're used in) seem to make no sense.  
Would some kind soul(s) please write (or collaborate on writing) an 
essay for the J Wiki explaining in great detail how dyadic "[" and "]" 
work and how to use them in both explicit and tacit verb definitions?  
AND include LOTS of examples?  Perhaps some portions of Chapter 12 of 
Henry Rich's "JfC" could be expanded as part of such an essay.

Thanks!

Harvey

P.S. Thanks, Raul, for using /. (Key)--this was eye-opening and 
potentially extremely useful in future scripts I might write!  That led 
me into noting that both Henry Rich's "JfC" and Roger Stokes' "LJ" have 
whole chapters (23 and 18, respectively) discussing such primitives--
I'm going to have to read those chapters (probably many times over!) 
because of their importance to my particular needs.  Thanks again for 
pointing me in this direction!

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to