Spectacular!
I was curious what "nc" was, because *I* don't remember defining that verb. I
discovered
nc
4!:0
That is, nc is "pre-defined" as a name for 4!:0. 4!:0 is the foreign function verb that
returns the "class" of a boxed name as an integer.[1] Is there a list of pre-defined
names for the foreign functions? (Or do I just have to read the source? :-)
Raul Miller's selector is about boxing the argument names with Words (;:),
classifying the argument names (with 4!:0, nc), differentiating nouns (class 0)
from verbs (class 3) with signum (*), and then using BaseTwo (#.) to distinguish
what the pair of arguments are. The selector is worth studying in itself, but the
model of & is clarity itself.
... peter
[1] http://www.jsoftware.com/help/dictionary/dx004.htm
Raul Miller wrote:
On Wed, Oct 24, 2012 at 3:27 AM, Linda Alvord <lindaalv...@verizon.net> wrote:
m&v y ↔ m v y This is the definition of bond (monadic)
u&v y ↔ u v y . This is the definition of compose (dyadic)
=&{: is the definition which I used earlier as =&{: B
I was told that I was using & dyadically so it was compose.
We need to be careful about using the word "it" in learning contexts.
Also, J grammar is regular, so we need to be very careful when
describing the use of that grammar.
In J, "dyad" refers to the combining definition (usually of a verb,
since verbs have two definitions), while "monad" refers to the
non-combining definition (usually of a verb...)
Anyways, I'm having a problem with "I was told that I was using &
dyadically so it was compose." because & in =&{: is compose but not
because & was being used dyadically.
The & itself is used dyadically in =&{: and in 1&+ and in *&2 but only
one of those is compose. And all three of those derived verbs have
both monadic and dyadic definitions. Instead "compose" would be
because both arguments to & were verbs. (Which was probably the
intent of the "it was compose" sentence, but the words were wrong for
me.)
It might be interesting to write a J conjunction which acts like &
ampersand=:2 :0
NB. monad
select. #.*nc;:'u v'
case. 0 do. assert. 0 NB. invalid
case. 1 do. m v y NB. left bond
case. 2 do. y u n NB. right bond
case. 3 do. ([: u v)"v y NB. compose monad
end.
:
NB. dyad (combining form)
select. #.*nc;:'u v'
case. 0 do. assert. 0 NB. invalid
case. 1 do. (m ampersand v)^:x y NB. left bond
case. 2 do. (u ampersand n)^:x y NB. right bond
case. 3 do. x (([: v [) u ([: v ]))"v y NB. compose dyad
end.
)
Note that I would need to introduce another level of abstraction if I
wanted an immediate syntactic warning for the invalid case.
amp=:2 :0
select. #.*nc;:'u v'
case. 0 do. assert. 0 NB. invalid
case. 1;2;3 do. u ampersand v
end.
)
Note also that this implementation displays differently from the
builtin (for the cases where the resulting derived verb is not used to
generate a result). But unless I have made an error these will
function the same way the built in works.
I hope this helps,
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm