• Re: NIL cons cell

    From Stefan Ram@21:1/5 to Daniel Cerqueira on Sat Jan 27 13:04:38 2024
    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 )).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniel Cerqueira@21:1/5 to All on Sat Jan 27 12:39:45 2024
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniel Cerqueira@21:1/5 to Stefan Ram on Sat Jan 27 13:23:10 2024
    [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.

    The notation `() for NIL does /not/ mean that NIL is represented
    by an empty cons cell.

    `(1 2) is `( 1 . ( 2 . NIL )).

    Then, if NIL is not represented by an empty cons cell, how is NIL
    represented?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Stefan Ram on Sat Jan 27 14:53:35 2024
    [email protected] (Stefan Ram) writes:
    A symbol is an entity of the source-code model.

    Well, the /name/ of the symbol is the actual entity of the
    source-code model.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Lars Brinkhoff on Sat Jan 27 14:49:19 2024
    Lars Brinkhoff <[email protected]> writes:
    NIL is a symbol (and also an (empty) list). Its internal representation
    is not specified by the standard.

    A symbol is an entity of the source-code model.

    A list is an entity of the runtime model.

    So, NIL "is" a symbol and a list (and also an atom), but on two
    different layers: In the source code it's a symbol, and the value of
    that symbol when it is being evaluated at runtime is the empty list.

    Models always contain entities which are not defined by
    being a kind of a more fundamental entity, because it is
    not possible to define every entity in that manner. But such
    entities are defined by their relations to other entities.

    Not defining the representation of entities gives Lisp the
    flexibility to be implemented in various ways on various machines.
    But it takes some time to get used to this kind of abstract thinking
    where abstract models replace specific internal representations.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lars Brinkhoff@21:1/5 to Daniel Cerqueira on Sat Jan 27 14:20:35 2024
    Daniel Cerqueira wrote:
    Then, if NIL is not represented by an empty cons cell, how is NIL represented?

    NIL is a symbol (and also an (empty) list). Its internal representation
    is not specified by the standard.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Daniel Cerqueira on Sat Jan 27 17:11:37 2024
    On 2024-01-27, Daniel Cerqueira <[email protected]> wrote:
    [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.

    Nonetheless, it *could* work that way. NIL could be internally
    represented as a cons cell, whose CAR and CDR are NIL (i.e. that
    cell it points to itself).

    If it is done correctly, the application cannot tell.

    I've not heard of that implementation strategy.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Daniel Cerqueira on Sat Jan 27 17:09:26 2024
    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.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Daniel Cerqueira on Sat Jan 27 20:25:09 2024
    On 2024-01-27, Daniel Cerqueira <[email protected]> wrote:
    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?

    It is safe to say that all proper lists have an empty proper list
    as their suffix! That empty list is nil.

    What is the suffix of (a)? It is () / NIL, which you can obtain
    using (cdr '(a)) or (rest '(a)).

    An empty list isn't a cons cell in Common Lisp and similar
    dialects; it is the symbol NIL.

    Note that (consp nil) is required to be false; i.e. it must
    return nil. Even if the implementation of NIL is a cons cell
    internally, that object must not report as a cons cell.

    (typeof nil) -> NULL

    (consp nil) -> NIL

    (atom nil) -> T

    (symbolp nil) -> T

    (symbol-package nil) -> #<package COMMON-LISP>

    (The #<package COMMON-LISP> will look different in your implementation;
    The #< characters introduce an implementation-specific notation
    that is not machine-readable.)

    NIL is defined by properties. Whatever kind of object it is, it
    has to satisfy the properties.



    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Madhu@21:1/5 to All on Sun Jan 28 06:59:16 2024
    * 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"


    Notice on the representation of NIL. Is this always an empty cons cell?

    No NIL is not a 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniel Cerqueira@21:1/5 to Madhu on Sun Jan 28 12:57:19 2024
    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. ;-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Daniel Cerqueira on Mon Jan 29 13:15:48 2024
    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.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniel Cerqueira@21:1/5 to Ben Bacarisse on Mon Jan 29 20:48:24 2024
    Ben Bacarisse <[email protected]> writes:

    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.

    Ok, thanks Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)