Sashikanth Chandrasekaran <[EMAIL PROTECTED]> wrote:
> Consider three operands: x, y1, y2 and the spread
> function, #^:_1 
>
> Isnt it true that if "y1 -: y2", then 
> "(x #^:_1 y1) -: (x #^:_1 y2)" ? 
>
> I understand that -: can return 1 for non-equal
> operands when they are equal under tolerant
> comparison. But in my example it does not appear that
> tolerant comparison should come into play.
>
> Here is my session output:
>
>    x
> +-----+
> |0 0 0|
> +-----+
>    y1
> ++
> ||
> ++
>    y2
> ++
> ||
> ++
>    y1 = a:
> 1
>    y2 = a:
> 1
>    y1 -: y2
> 1
>    x #^:_1 each y1
> +----+
> |++++|
> ||||||
> |++++|
> +----+
>    x #^:_1 each y2
> +-----+
> |0 0 0|
> +-----+
>
> The problem appears to be with the fills used by
> #^:_1.
> For y1, it is using a: as the fill and for y2 it is
> using 0 fills. I extracted y1 and y2 from a larger
> array and although y1 -: y2 returns 1 and they are
> both equal to a:, there is some difference which I am
> unable to figure out. (I did not include the program
> that generated this array because it is fairly large).
> When I explicitly create y1 and y2, I get the expected
>
> behavior. 

Welcome to the twilight zone created by empty arrays.
There are many places in J (and its predecesor APL)
where empty arrays cause problems that don't normally
exist in other areas. In this case, -: checks to make sure
that the shapes and all items of y1 and y2 comform.
Since they have no items, they automatically conform,
even though y1 and y2 may be of different types
(for example, y1 is an array containing no boxes, while
y2 is an array containing no numbers).

There is a whole class of humor, called "empty array humor"
spawned by this kind of ambiguity. For example:

  "Waiter, could I please have a cup of coffee without cream?"
  "Sorry, we don't serve cream, only milk."
  "OK, then I'll have a cup of coffee without milk."

J nouns are strongly typed (you get a domain error if
you try something like 'a',3). However, empty nouns
appear to be weakly typed, in that you can combine
them with non-empty nouns, and the type of the empty
noun is adjusted to conform (for example, 3,'' or 'a',i.0)
You often find '' being used in place of an empty numeric
list, since there is no way to enter such a list directly.

However, even though typing of empty nouns is weak,
it still exists, and can show itself when fills are being used
(for example, wth take {. reshape $ or expand #^:_1)

(This would be analagous to handing a waiter an empty
glass of milk and an empty glass of juice and asking for
refills. Before you ask, the glasses are identical, but they
are quite different when you get them back).
 
> Can someone suggest how I could go about finding out
> the difference between the y1 and y2 that I extracted
> from the larger array? 
> Thx, -sashi.

You can use 3!:0 to get the exact type of a noun.
It is then up to you to decide just which types are
sufficiently identical for your purposes.

-- Mark D. Niemiec <[EMAIL PROTECTED]>


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

Reply via email to