Recovering the once true meaning of type NIL in LOOP

<[email protected]> Tue, 5 Dec 2017 14:53:32 +0000
Newsgroups gmane.lisp.clisp.general
Message-ID <c02ab52667f844498aeca73d392bafe2@HE105658.emea1.cds.t-internal.com>
Hi,

if you, like me, have always wondered why CLtL2 and ANSI-CL special-case the type NIL
(among fixnum, float, T and NIL) in LOOP destructuring, here's a satisfying answer.

NIL is a valid type, cf. http://clhs.lisp.se/Body/t_nil.htm but, as useful as it is for
reasoning about type hierarchies or (VECTOR NIL #), you don't want it as type
declaration for a variable, because then you can't bind anything to that variable!

Consider (macroexpand-1'
(LOOP for (i j k) of-type (fixnum) across #())
Both CLISP and the CMU loop code from the CMU AI repository generate forms like:
-> (declare (type NIL j)) ; actually (type (or null NIL) j) in clisp 
That's useless.

NIL has a special meaning in destructuring:
- as a variable name, that position is ignored (explicitly in CLtL2 and ANSI-CL);
- as a type, both CLtL2 and ANSI-CL are silent.

The above input is different from (fixnum NIL NIL), yet from the *typical* destructuring
tree walking, one can derive that the subtree (j k) must share the type information NIL.
Now if you consider that to mean "no information" (or, like with variables, "don't care")
for the rest of the variable tree starting at that node, instead of the unpractical type NIL
for a variable, it all suddenly starts to make sense.

And indeed, that's what the ancient MIT LOOP code generates:
No type declaration for variables declared of type NIL!

So here's a patch for clisp to do the same (even though clisp mostly ignores types).
With it, clisp and MIT LOOP destructuring look strikingly similar.

Why it was important for ancient implementations to distinguish a generic type
declaration, e.g. (type T i), from no type declaration at all is beyond me, but,
with these 2 choices, you, the programmer, are in control.

Regards,
	Jörg
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-list