file: job.t package: muf status: alpha
The cons
function takes two values and constructs a
List cell containing them as it's car
and cdr
:
Stack: "a" "d" cons -> cell Stack: cell car cell cdr Stack: "a" "d"
The name is short for "construct", since it constructs a
cons
cell, the basic unit of storage in classical
lisp systems.
List cells are often called "cons cells", since they are
constructed by cons
, or simply "conses", and the
process of constructing them is often called "consing".
It is possible to implement arbitrary programs using only
cons
to modify memory; This train of thought leads to the pure-functional programming community. If this intrigues you, you might grab a Haskell implementation from cs.yale.edu or join the mailing list via haskell-request@cs.yale.edu.
You may sometimes wish to allocate a cons cell
on the stack instead of on the heap: The function
ephemeralCons
will do this. For brevity,
it is also available under the synonym econs
.
The usual cautions pertaining to ephemerals
apply: See section ]makeEphemeralVector.
Go to the first, previous, next, last section, table of contents.