Concerning the behaviour of insert / when the argument has one item.

e.g.

   u/  i.1 4

Henry Rich wrote on Sept 8th:

http://www.jsoftware.com/pipermail/programming/2007-September/008052.html

> If y has only one item, the result of u/ y is that item, for any u.
> It makes sense as
> (Item -#y) u ... u (Item _2) u (Item _1)
> where if there is no item _2, the sequence ends with item _1.

But this does not follow from the Vocabulary entry:
http://www.jsoftware.com/help/dictionary/d420.htm
=====================================================
If y has no items (that is, 0=#y), the result of u/y is the neutral or
identity element of the function u .
A neutral of a function u is a value e such that x u e ↔ x or e u x ↔ x,
for every x in the domain (or some significant sub-domain such as boolean)
of u .

This definition of insertion over an argument having zero items extends
partitioning identities of the form u/y ↔ (u/k{.y) u (u/k}.y) to the cases k
e. 0,#y .
=====================================================

In other words, when k = 1 then

u/y ↔ (u/1{.y) u (u/1}.y)

But this is not what happens now:

u =. 0:
y =. i. 1 4

u/y
0 1 2 3

   (u/1{.y) u (u/1}.y)  NB.
|domain error
|   (u/1{.y)u(    u/1}.y)

And that is what should happen.
The 'domain error' occurs because the function 0: does not
have an identity element.

Based on this, the current behaviour of / is wrong.

The current behaviour also leads to some pretty nasty program faults.
For example, if the domain of u is numeric but its range is character, then
the current implementation u/ returns a numeric result for
a 1-item array - after which nastiness may be expected.
Furthermore, because in the 1-item argument case, u isn't invoked
no protection is possible against such nastiness.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to