5 ms·
It could simplify things elsewhere. In Lisp, CAR and CDR accessors take a cons cell or NIL, which isn't a cons cell, and has no such fields. It wasn't always
by kazinator 11y ago
It could simplify things elsewhere.
In Lisp, CAR and CDR accessors take a cons cell or NIL, which isn't a cons cell, and has no such fields.
It wasn't always like that; according to the HOPL paper on evolution of Lisp, InterLisp introduced this nicety and it was copied by others.
These functions are complicated with that extra state, but programs are simplified.
A null "char *" indicating "this object has no name" is better than some special string value doing the same, because it's different from every possible string value.
- rtpg 11y agoI'm not saying a special string value, but a wrapper object with an "existence" bit. You can then assume, if the existence bit is flipped right, that the char* "exists". This is functionally equivalent, but forces existence checks when they're needed. And by removing "null" from your vocabulary, an entire class of errors disappears. With C this is a bit trickier to ensure. But I think the design pattern can still be useful. And it doesn't make code more complicated, but rather it makes the complicated aspects explicit . Instead of testing that name == null, you test that name.exists is False, and if not you use name.value. And you make null a banned word in your codebase. The result is that you _never_ have to ask "is this char* possibly null?". The answer is always "no". So you remove superfluous checks I think this pattern works much better when you have stronger type checking, though...