Re: Remove and delete on an array...
* Bob Hutchison wrote:
> But isn't nil a sub-type of all types, or am I misinterpreting the
> hyper spec? Why can't nil be put into the array after a delete? That is
> what I do in the functions I now use instead of delete/remove (BTW,
> what I meant by 'null' is something that allows the 'null' function to
> return true).
yes, you are. The *type* NIL is a subtype of all types, but there are
no objects which are of that type. NIL is of type NULL, which is not
a sub-type of all types (in fact it's a subtype of LIST and SYMBOL or
something).
I guess it would be possible to make a special object (possibly even
NIL) which was the only instance of a type which was a sub-type of all
types, but the consequences would be bad I think. Type checks would
be worse since you'd always have to check for this type, and it would
become hard to implement arrays of immediate types. For instance
consider an array of (UNSIGNED-BYTE 8)s: if you use a compact
representation (byte-aligned in other words) then, other than the
header, all bit patterns in the array are legal values. So you can't
use such a representation if you want to be able to have a special
null value.
Java cops out on this by distinguishing in the language between
immediate types and non-immediate ones, and having null be an instance
of only non-immediate types. Until very recently this has meant user
code has had to explicitly box and unbox things all over the place,
which is a horror. They've got away from that now (at least mostly)
but the type system is still really ugly.
Of course, in CL you can still arrange to have arrays which can
contain NIL by making their element type (OR FOO NULL). And you could
argue that in 99% of cases where you want to do this the upgraded
array element type will be T anyway, so there is no cost. But there
is a cost, since now any implementation which wants to do serious type
inference has to emit checks for NIL all over the place.
> And in my case, leaves me in a situation where I can't use the built in
> functions.
Yes, it does. The same way it does in Java (say) of course - you
can't use arrays of things to do what you want, you have to use some
bit of library code. such as ArrayList or something (which has a
syntax which is radically different than real arrays). Java's
advantage is really that they've standardised the library. The
disadvantage is that nothing you can do is going to make ArrayLists
look like arrays - foo.get(n) is not really like foo[n], and
assignment is worse - foo.set(n, o) vs foo[n] = o. Yuck! In CL at
least you can dress up your ARRAY-LIST objects with a proper accessor
so (say) (ref x i) works and (setf (ref x i) n) does what you think,
even when x is a real array not an ARRAY-LIST.
Anyway, this isn't anything to do with LW really, it should be on cll
or something (which I don't read any more, so, well...)
--tim
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________