Henry wrote:
> g@[&0
Alex G. responded:
> But how on earth do you parse that?? Sure beats me.
TL;DR: The last sentence of the Vocabulary entry for & is "The phrase x
f@[&0 y is equivalent to f^:x y , apply the monad f x times to y ." But if
you want to know why....
It breaks down like this:
&
@ 0
g [
That is, the workhorse here (the root of the tree) is &, so that's where
the magic must be.
So, let's follow that path where it leads. First, we notice that & has two
arguments: an atomic right argument, the noun 0, and a composite left
argument, the verb g@[ .
Going further, we refer to the Vocabulary, where turns out there are two
flavors of & : one where both arguments are verbs, and another where one is
a noun. Since our right argument is a noun, we want the latter.
When we follow that path, we find it forks again: here, we must choose
whether we want the dyad or the monad. Now, in isolation, we can't know for
sure whether the author intended this verb to be called with one argument
or two. But, there are clues lying around that might point us in the right
direction.
The first clue is that @[ part. Most often, that's an indication that the
overall verb takes two arguments, but this piece of it only cares about the
left one. We can't say with certainty that's what's going on, especially
with an argument-adder like & in the mix, but it's a pretty good bet.
The bigger clue is that we already know where the monadic path leads, we've
been down it often: (verb&noun y) is simply (y verb noun), as in %&2
(halve) or -&1 (decrement) or ,&' ' (append) etc. There's a lot of power
there, but no mystery (and no magic).
So let's take the road less travelled. We can always back up later if we
took a wrong turn. So, now we're looking at the dyadic definition of (verbs
derived from) & .
Again, our path forks. The Vocabulary gives us two choices:
x m&v y
x u&n y
Since the DoJ's convention is that u and v are verbs while m and n are
nouns, and we're looking for a pattern like:
x (verb&noun) y
we know we want x u&n y .
Let's follow that last little trail:
x u&n y ↔ u&n^:x y
Well, look at that, ^: shows up, out of nowhere! We've found the source of
the magic. Let's pick it up and take it home, retracing our path.
Now, the first turn is the trickiest! The u&n on the left is the magic
one, the mysterious one; the u&n one the right is the familiar one, the
"halve" one, the "decrement" one. We must turn right, down the familiar
path, or we'll just end up going in circles.
Following our course backwards (carefully!), we come across, in order:
x u&n y ↔ u&n^:x y
x (verb&noun) y ↔ verb&noun^:x y
x (g@[&0) y ↔ g@[&0 ^:x y
Hmm. Now what? g@[&0^:x y is suggestive, but we still have that
troublesome &0 in there (though now it's been reduced to the familiar &,
not the mysterious & that gave us our magic ^: ). We'll have to find a way
around that obstacle to get home.
The first obstruction is that ^:x is in the way of us getting to the (new,
reduced) &0 . Let's clear that away. We know that in J-algebra:
verb^:x y
is equal to:
verb verb verb ... verb y
^----- x times -------^
So:
g@[&0 g@[&0 g@[&0 ... g@[&0 y
^------- x times ---------^
Hmm. Past the blockade, but now we face a sea of verbs. Let's take this one
step at a time. The first is, obviously:
g@[&0 y
At least we can get to the & now. And in fact, we know it's just the
familiar one, so we can change this to:
y (g@[) 0
And what do you know, our original intuition was correct! This is a
function of two arguments, but this piece of it only cares about the left
argument*. So now we have:
g y
But what about all those other g@[&0 ? Of course, they're susceptible to
the same analysis. Like stones in a pond, each small step leads to another!
g g g g g ... g y
^-- x times --^
We're home!
g^:x y
-Dan
PS: Did you notice the sleight of hand? We turned x g@[&0 y into g^:x y ;
the zero simply disappeared! Poof.
In fact, no matter what we put there, it would have disappeared.
f =. g@[&' now you see me! '
45 f 27
4616
* Which turns out, abracadabra, to be the right argument.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm