newLISP cells question

Started by ryuo, June 06, 2014, 04:52:53 PM

Previous topic - Next topic

ryuo

Let me see if I understand this. newLISP cells are internally composed of:



an integer to track the type

a linked list pointer

1st part of integer/floating point or string length

2nd part of integer/floating point or string or symbol address



So, a newLISP list is implemented as a linked list with each newLISP cell occupying an entry in the linked list? The last two entries appear to vary in interpretation depending on the cell's type.



From http://www.newlisp.org/downloads/newlisp_manual.html#nil_and_true">http://www.newlisp.org/downloads/newlis ... l_and_true">http://www.newlisp.org/downloads/newlisp_manual.html#nil_and_true :


Quote
A list in newLISP is a newLISP cell of type list. It acts like a container for the linked list of elements making up the list cell's contents. There is no dotted pair in newLISP because the cdr (tail) part of a Lisp cell always points to another Lisp cell and never to a basic data type, such as a number or a symbol. Only the car (head) part may contain a basic data type. Early Lisp implementations used car and cdr for the names head and tail.


So a newLISP cell can only contain a single object? Meaning, it can only store one integer, floating point, string, pointer to a list, or other object type? In the case of a list, the newLISP cell appears to store a pointer to another newLISP cell which is the start of a different list of cells. The main part I do not understand is the Head vs Tail details of a cell. What is the Head and Tail of a cell? I thought these were in regards to the list of cells as a whole. Any help would be appreciated.

rrq

#1
As I understand it from having browsed the code, a list is represented in a succession of CELLs where the "contents" fields point to the list members. Thus, a list like (1 2) of two elements would be represented by 4 CELLs, two of which are  list cells and two are integer cells. The Head (aka contents) of the first list cell points to the CELL holding integer 1, and the Tail of it (aka next) points to the second list cell. Likewise, the second list cell points to the 2 cell and the nil cell (which has a special cell type).

And as an implementation level side  note, the "aux" field of a list cell is used as a short-cut that generally points to the last element of the list (or nil or true).