There is no direct concept of the distinctions between nil data and empty data in J, but you can use i.0 and i. 0 0 as close approximations.

In data management, the two separate concepts are used to strongly distinguish data that has yet been evaluated from data that is evaluated to be nothing. This essay is about the distinctions and pitfalls of i.0 and i. 0 0.

i. 0 and i. 0 0 are different. Here is how:

i.0 will print a blank line in the Jconsole. i.0 0 will not.

As a practical matter, consider i.0 to be the empty element, while i.0 0 is nil.

Verbs that set no return value, return i.0 0

0# rank1list returns i.0 , but 0#rank2+table doesn't: in general 0#array produces a new array with the same shape except the first axis has length 0.

   (i.0) -: (0# 3$i.12)
1
   (i.0) -: (0# (3 4$i.12))
0
   $ (0# (3 4$i.12))
0 4
   (i.0 4) -: (0# 3 4$i. 12)
1
   (i.0 0) -: (0# 3 4$i. 12)
0

   f=: 3 : 'if. 1 do. return. end.'
   (i. 0 0) -: f ''
1
   '' -: i.0
1

   (i. 0 0) -: +: i. 0 0
1
   (i. 0 0) -: +: i. 0 
0
   (i. 0) -: +: i. 0 
1
   (i.0) -: (i.0 )  + i.0
1
    3  , i.0
3
   (i.0) -: 3  , i.0 0
0
   (i.0 0) -: 3  , i.0 0
0
   (i.1 0) -: 3  , i.0 0 NB. yuk... depending on nil meaning can be unreliable.
1
    3 4  , i.0 0
3 4
   $ 3 4 
2
   $ 3 4 , i. 0 0 NB. usually not what you want when appending nil, but results look ok only if initial list has more than 1 item.
1 2
   $ (3 4 , i. 0 0) , i. 0 0
1 2

i. 0 is 0$0

i. 0 0 is 0 0 $ 0

The display of a rank-2 array is each line, with LF appended to the end of each line.

So, for 0 0 $ 0 you get no lines, no LF.

for 0 $ 0 you get one (empty) line, ended by LF

+/ applied to an empty list produces an identity item: an item made up of identity elements.

When the / adverb is used with i. 0 and i. 0 0 the results are different. The items of i. 0 are scalars, so u/ i. 0 produces an identity item that is a scalar. The items of i. 0 0 are 0-length lists, so u/ i. 0 0 produces an identity item that is a 0-length list.

   +/ i.0
0
   (i.0) -: +/ i.0 0 NB. u/ nil is empty
1
   (i.0) -:(i.0) + 3 NB. identity function only defined for / adverb
1

+/ 0 $ 0 the item is a scalar, there are none of them,

+/ 0 0 $ 0 the item is a 0-length list, there are none of

0

PascalJasmin/nil and empty in J (last edited 2008-12-08 10:45:41 by )