[Jprogramming] Item amend ~: index error.
Pascal Jasmin
godspiral2000 at yahoo.ca
Sun Mar 30 17:35:34 UTC 2014
I'm sure your explanation is helpful to many, but the reason for my comment comes from the natural frustrations of "I wish the computer would do what I meant instead of what I say" moments and then the obvious consequence of obviously "I don't always understand what I say.", which even if we all acknowledge to be true, is not the foremost thought when debugging/troubleshooting.
~ is the demon that will haunt beginners the most. Passive is by far the most common use of ~, and the most intuitively understandable (though all 3 are fairly quite straightforward), but its conceptually linked most directly to Passive.
I do not like or recommend the practice of replacing J primitives with words such as 'verb define' because it obfuscates the parsing understanding needed to read and write J. However, in the case of ~, (though I don't do it), it would have saved me many headaches if I had defined 3 adverbs and used them.
For interest what is said with: (i. 3 3) }~ (0 1 2) is:
0 1 2 (i. 3 3) } 0 1 2
On another note, } is overly complicated, and IMO poorly designed, though Eelvex's example is something I just learned today towards explaining it.
(0 1 2) } (i. 3 3)
0 4 8
the above is incredibly cool, as it retrieves the diagonal from i. 3 3. But note, the unfortunate asymetry with { which would have made a more approachable design decision:
(0 1 2) { (i. 3 3)
0 1 2
3 4 5
6 7 8
so, this happens:
1 (0 1 2) } (i. 3 3)
1 1 1
1 1 1
1 1 1
+: (0 1 2) } (i. 3 3)
0 8 16
(0 1 ) } (i. 3 3)
|length error
| (0 1)}(i.3 3)
(0 1 ) { (i. 3 3)
0 1 2
3 4 5
The key to understanding }'s behaviour is that m} has both a monadic and dyadic verb result. Which is completely unobvious for something called amend. (An intuitive imagination based understanding (as opposed to RTFM based understanding which separates item amend from amend definitions) would be that n} returns an adverb instead of a verb, which can then take u or m to update y.
I recommend using the following conjunction most of the time:
amend_z_ =: 2 : 0 NB. v is n or n{"num
s=. v"_ y
(u"_ (s{y)) (s}) y
:
s=. v"_ y
(x u"_ (s{y)) (s}) y
)
Though it loses the quirky feature of obtaining the diagonal (Item Amend), it gains the feature of updating y in an intuitive (symetrical to {) way that accepts a verb for the updating.
+: amend ( 1 2) i. 3 3
0 1 2
6 8 10
12 14 16
3 + amend 1 +: amend ( 1 2) i. 3 3
0 1 2
9 11 13
12 14 16
the gerund } is weird too. Here is a result I don't understand (might be a bug?):
3 +`((0 0;1 1;2 2)"1)`]} i.3 3
9 1 2
3 10 5
6 7 11
----- Original Message -----
From: Dan Bron <j at bron.us>
To: "programming at jsoftware.com" <programming at jsoftware.com>
Cc:
Sent: Sunday, March 30, 2014 9:16:51 AM
Subject: Re: [Jprogramming] Item amend ~: index error.
You can tell immediately whether ~ is performing passive, reflexive , or evoke.
Did you pass it a noun? Then it's evoke (this is very rare and very obvious: remember, as an adverb, ~'s argument is fixed at runtime, so you'd literally have to write or see a noun directly to the left of ~).
You didn't pass it a noun? Ok, by definition, you passed it a verb. So ~ consumed that verb and produced a new verb. Did you pass that new verb one argument, or two arguments?
If you passed the new verb one argument (aka "invoked the monad") then ~ will act in its reflexive capacity. If you passed the new verb two arguments (aka "invoked the monad") then ~ will act in its passive capacity.
In other words, f~ ↔️ (] f ]) : (] f [) . That is, given a verb f, f~ will produce an ambivalent verb which will always invoke the dyadic valence of f (the monadic valence of f is thus ignored and therefore irrelevant). When f~ is invoked, the left argument to f will always be the right argument of f~ .
Thus, the only difference between passive and reflexive is the right argument to f, which will be the left argument of f~ if it has one (ie if f~ was invoked dyadically) or the same old right argument as before if it doesn't (ie if f~ was invoked monadically and the only argument around to use is on the right).
So ~ is hardly a demon from hell, because you know what you're getting when you invoke it. The incantations are simple and the consequences predictable.
-Dan
Ok, need a mnemonic?
'name'~ : evoke the name (call upon, summon up, conjure, recall)
verb~ y : reflect the argument (mirror, create a perfect image, clone, put a mirror up so the verb sees two identical copies, etc)
x verb~ y : use the passive voice (switch the subject and object, invert the sentence, etc):
Pascal invoked Astaroth
Astaroth was invoked by Pascal
[do not try this at home]
[1] "Why was ~ on a dyadic verb named "passive"?
http://www.jsoftware.com/pipermail/general/2007-May/030070.html
Sent from my iPhone
> On Mar 30, 2014, at 8:31 AM, Pascal Jasmin <godspiral2000 at yahoo.ca> wrote:
>
> } is an adverb.
> ~ is a demon from hell for errors in that it can do one of 3 things (passive, reflex, evoke), and often its one of the other 2 than you intended. (here you were assuming it would do passive). I'm not 100% positive which of the other 2 it actually gets parsed at here.
>
>
> ----- Original Message -----
> From: EelVex <eelvex at gmail.com>
> To: Programming forum <programming at jsoftware.com>
> Cc:
> Sent: Sunday, March 30, 2014 7:07:05 AM
> Subject: [Jprogramming] Item amend ~: index error.
>
> (0 1 2) } (i. 3 3)
> 0 4 8
>
> (i. 3 3) }~ (0 1 2)
> |index error
> | (i.3 3)}~(0 1 2)
>
> Why? What's the use of }~ when not used as 'amend'?
> ----------------------------------------------------------------------
> 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
More information about the Programming
mailing list