Null object: Difference between revisions

J: attempt to more adequately describe how we fill in the holes in the description of holes as represented in the language
(J: attempt to more adequately describe how we fill in the holes in the description of holes as represented in the language)
Line 470:
 
=={{header|J}}==
J doesn't have an untyped NULL. Instead, it has a concept of "fill". Numeric fill is 0, character fill is the space character, and boxed fill is the ace (a:) which is an empty box. Fill is what is used to pad an array structure when that is needed. (And some operations support using a user specified value in place of the default fill.)
J doesn't have NULL. To indicate "missing data", "normal" data is usually pressed into service (e.g. <tt>0</tt> or <tt>_1</tt> in a numeric context, <tt>' '</tt> in a literal context, <tt>a:</tt> in a boxed context, etc). Frequently, missing data is represented by the empty vector <tt><nowiki>''</nowiki></tt>, or other arrays without any elements.
 
J doesn't have NULL. To indicate "missing data", "normal" data is usually pressed into service (e.g. <tt>0</tt> or <tt>_1</tt> in a numeric context, <tt>' '</tt> in a literal context, <tt>a:</tt> in a boxed context, etc). Frequently, missing data is represented by the empty vector <tt><nowiki>''</nowiki></tt>, or other arrays without any elements.
However, undefined names in J can be identified:
 
That said, undefined names in J are not associated with any data of any type. Furthermore, any attempt to use the value of an undefined is treated as an error (this is distinct from the concept of an empty array, which contains no data but which is not an error to use). However, it is possible to check if a name is defined before attempting to use it:
 
<lang J>isUndefined=: _1 = nc@boxxopen</lang>
Line 484 ⟶ 486:
0</lang>
 
Note, howeverof course, that this "name is not defined" state is not a first class value in J -- you can not create a list of "undefineds".
 
NoteFinally, note: the concept of an empty array can be natural in J (and APL) for representing data which is not there -- it is the structural equivalent of the number zero. That said, its implications can sometimes be non-obvious for people coming from a languages which requires that arrays have content. As a result, you will sometimes encounter empty array jokes...
 
:Marie Pennysworth, having spent a productive day shopping, stopped by Robert Cuttingham's butcher shop.
Line 498 ⟶ 500:
:He smiled, "When I am out, I only charge seven dollars a pound."
 
That said, note that thea usualtypical way to indicate missing or invalid data, in J, is to have a parallel array which is a bit mask (which selects the desired or valid values and, by implication, does not select the invalid values). Or, as a logical equivalent: a list of indices which select the desired and/or valid values. Alternatively, you can have an array without the invalid values and a bit mask which demonstrates how the data would be populated on a larger array -- in other words instead of 3,4,null,5 you could have (3 4 5) and (1 1 0 1). And you can transform between some of these representations:
 
<lang j> 1 1 0 1#3 4 _ 5
6,962

edits