Subject: UN: strange behaviour of a&+ in J?
From: richard.levine@canrem.com (Richard Levine)
Date: Thu, 27 Apr 95 22:45:00 -0500
Organization: CRS Online  (Toronto, Ontario)

In a recent communication, it was pointed out that the
following sequence gives a domain error.

   f=.a&+
   a=.7
   f 2
|domain error
|       f 2

... whereas the following executes to completion:

   b=.7
   h=.b&+
   h 2
9

I found this rather mysterious until I looked up the "bond/compose"
conjunction (&) in the Dictionary.

As pointed out, in the first example, "a" is an undefined symbol that,
being undefined, is treated as a verb.  (This is mentionned
explicitly in the latest (1995) edition of the
Dictionary, page 80.  "An unassigned name [is] treated as a verb.")

Therefore, when "a" is unassigned, f=.a&+ is a use of the
"compose" (&) conjunction, which takes two verbs as arguments,
and returns a verb result, namely:

a + y.

"a" is expected to be a verb, otherwise, there is a domain error.
If "a" is a verb, there is no error.  For example,

   erase
4!:55
   erase 'a'
1
   f =. a&+
   a =. -
   f 10
_10

If "a" is something other than a verb, it will be outside the domain
of the verb a&+, and therefore a "domain error" will be generated.

If "a" is a noun, then the expression a&+ is an example of the
"bond" (&) conjunction,
which takes two arguments, a noun and a dyadic verb,
and returns a monadic verb.  Note that J appears to use the value of
the noun directly in this case, as shown in the following sequence:

   a =. 10
   f =. a&+
   f
10&+
   f 9
19

Thanks to all for sharing this strange behaviour which is no longer
so strange any more.

--RL
