Notice on the representation of NIL. Is this always an empty cons cell?
Daniel Cerqueira <[email protected]> writes:
Notice on the representation of NIL. Is this always an empty cons cell?
NIL is a special value that is /not/ the same as `(NIL . NIL),
which is a dotted pair ("cell") with its CAR and CDR being NIL.
The notation `() for NIL does /not/ mean that NIL is represented
by an empty cons cell.
`(1 2) is `( 1 . ( 2 . NIL )).
A symbol is an entity of the source-code model.
NIL is a symbol (and also an (empty) list). Its internal representation
is not specified by the standard.
Then, if NIL is not represented by an empty cons cell, how is NIL represented?
[email protected] (Stefan Ram) writes:
Daniel Cerqueira <[email protected]> writes:
Notice on the representation of NIL. Is this always an empty cons cell?
NIL is a special value that is /not/ the same as `(NIL . NIL),
which is a dotted pair ("cell") with its CAR and CDR being NIL.
You are defining NIL with NIL, which is a poor, and confusing teaching.
I am wondering about the cons cell representation of NIL.
For example, with '(1 2) , is the representation like this:
+---.---+ +---.---+ +---.---+
| 1 | .---->| 2 | .---->| | |
+---.---+ +---.---+ +---.---+
Notice on the representation of NIL. Is this always an empty cons cell?
I am wondering about the cons cell representation of NIL.
For example, with '(1 2) , is the representation like this:
+---.---+ +---.---+ +---.---+
| 1 | .---->| 2 | .---->| | |
+---.---+ +---.---+ +---.---+
?
Notice on the representation of NIL. Is this always an empty cons cell?
Is it safe to say that all proper lists end with an empty cons cell?
On 2024-01-27, Daniel Cerqueira <[email protected]> wrote:
I am wondering about the cons cell representation of NIL.
Nil isn't formally a cons cell.
For example, with '(1 2) , is the representation like this:
+---.---+ +---.---+ +---.---+
| 1 | .---->| 2 | .---->| | |
+---.---+ +---.---+ +---.---+
A CL implementation can represent nil in any way it wants as long as it
is consistent with the language. It is possible for nil to *internally*
be a cons cell object (provided it's only one global object).
Notice on the representation of NIL. Is this always an empty cons cell?
In some impelmentations, it's not a heap allocated object at all, but
a special unboxed value.
Formally, nil is of symbol type. (symbolp nil) has to yield true,
and everything has to work: (symbol-name nil), (symbol-package nil).
In a system where nil is a special bit pattern, and not a pointer
to a symbol object, all those functions have to check for nil as
a special case.
* Kaz Kylheku <[email protected]> :
Wrote on Sat, 27 Jan 2024 17:09:26 -0000 (UTC):
On 2024-01-27, Daniel Cerqueira <[email protected]> wrote:
I am wondering about the cons cell representation of NIL.
Nil isn't formally a cons cell.
For example, with '(1 2) , is the representation like this:
+---.---+ +---.---+ +---.---+
| 1 | .---->| 2 | .---->| | |
+---.---+ +---.---+ +---.---+
A CL implementation can represent nil in any way it wants as long as it
is consistent with the language. It is possible for nil to *internally*
be a cons cell object (provided it's only one global object).
(consp nil) has to be true. NIL cannot be of type CONS.
It makes no sense to say NIL can be implemented using a "cons cell object"
Madhu <[email protected]> writes:
* Kaz Kylheku <[email protected]> :
Wrote on Sat, 27 Jan 2024 17:09:26 -0000 (UTC):
On 2024-01-27, Daniel Cerqueira <[email protected]> wrote:
I am wondering about the cons cell representation of NIL.
Nil isn't formally a cons cell.
For example, with '(1 2) , is the representation like this:
+---.---+ +---.---+ +---.---+
| 1 | .---->| 2 | .---->| | |
+---.---+ +---.---+ +---.---+
A CL implementation can represent nil in any way it wants as long as it
is consistent with the language. It is possible for nil to *internally*
be a cons cell object (provided it's only one global object).
(consp nil) has to be true. NIL cannot be of type CONS.
It makes no sense to say NIL can be implemented using a "cons cell object"
Thanks Madhu. That simple explanation makes perfect sense. Didn't
thought of that. ;-)
Daniel Cerqueira <[email protected]> writes:
Madhu <[email protected]> writes:
* Kaz Kylheku <[email protected]> :
Wrote on Sat, 27 Jan 2024 17:09:26 -0000 (UTC):
On 2024-01-27, Daniel Cerqueira <[email protected]> wrote:
I am wondering about the cons cell representation of NIL.
Nil isn't formally a cons cell.
For example, with '(1 2) , is the representation like this:
+---.---+ +---.---+ +---.---+
| 1 | .---->| 2 | .---->| | |
+---.---+ +---.---+ +---.---+
A CL implementation can represent nil in any way it wants as long as it >>>> is consistent with the language. It is possible for nil to *internally* >>>> be a cons cell object (provided it's only one global object).
(consp nil) has to be true. NIL cannot be of type CONS.
I think you meant to write "NIL" (or maybe "not true").
It makes no sense to say NIL can be implemented using a "cons cell object" >>Thanks Madhu. That simple explanation makes perfect sense. Didn't
thought of that. ;-)
Simple but not entirely accurate! Kaz said that the implementation can
use any representation it wants *internally* provided it is consistent
with the language. Since the implementation also defines consp (and
atom, etc.), it can return NIL when passed that internal representation
which can indeed be a cons cell.
I've seen it done, though not in a Common Lisp implementation.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 714 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 133:56:16 |
| Calls: | 12,087 |
| Files: | 14,997 |
| Messages: | 6,517,349 |