cons - construct a pair
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
(cons obj1 obj2)
Returns a newly allocated pair whose
The pair is guaranteed to be different (in the sense of eqv?) from
every existing object.
There is not a lot of room for differences between implementations
The main difference will be in how fast a pair can be allocated
and how allocation affects the garbage collector.
It is possible for an implementation to return a pair that cannot be
changed (also known as an immutable pair), but this is not standard.
Pairs in Racket are immutable. This does not apply to its R6RS language.
Returns a new pair. If the cdr is a list then the return value is also
considered to be a list.
(cons 'a '()) => (a)
(cons '(a) '(b c d)) => ((a) b c d)
(cons "a" '(b c)) => ("a" b c)
(cons 'a 3) => (a . 3)
(cons '(a b) 'c) => ((a b) . c)
procedure is used in programs that work with lists or other
structures that consist of pairs.
In many cases it can be better to process a list with procedures like
or one of the procedures from SRFI-1.
Larger structures can be created with
which lets the code resemble the structure it creates.
Pairs are a fundamental data structure.
procedure appears in all Lisps.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
The wrong number of arguments was passed.
The assertions described above are errors.
Implementations may signal an error, extend the procedure's
domain of definition to include such arguments,
or fail catastrophically.
The predecessor of
was a subroutine cons(a,d,p,t) along with
car, cdr, cpr, and ctr.
came from Herbert Gelernter and Carl Gerberich at IBM during the
development of the FORTRAN List Processing Language
(History of Lisp, John McCarthy, 1979).
The Lisp in
MIT AI Memo No.~1 (September 1958)
uses the four-argument
The modern two-argument
MIT AI Memo No.~3.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.