In computer programming, cons
( /ˈkɒnz/ or /ˈkɒns/) is a fundamental function in most dialects of the Lisp programming language. cons
constructs memory objects which hold two values or pointers to values. These objects are referred to as (cons) cells, conses, non-atomic s-expressions ("NATSes"), or (cons) pairs. In Lisp jargon, the expression "to cons x onto y" means to construct a new object with (cons x y)
. The resulting pair has a left half, referred to as the car
(the first element), and a right half (the second element), referred to as the cdr
.
It is loosely related to the object-oriented notion of a constructor, which creates a new object given arguments, and more closely related to the constructor function of an algebraic data type system.
The word "cons" and expressions like "to cons onto" are also part of a more general functional programming jargon. Sometimes operators that have a similar purpose, especially in the context of list processing, are pronounced "cons". (A good example is the :: operator in ML and Scala, which adds an element to the beginning of a list.)
Read more about Cons: Use, Use in Conversation, Not Technically Fundamental
Other articles related to "cons":
... operation (referring to MACLISP's cons function) and the infix @ operation (referring to MACLISP's append function) a.(b@c) = (a.b)@c The preceding example ...
... Cons-la-Grandville is a commune in the Meurthe-et-Moselle department in north-eastern France ... The Château de Cons-la-Grandville is situated in the middle of the village ...
2001 Jeonbuk Hyundai Motors) Jamie Cureton (2003 Busan I’Cons) Andy Cooke (2003–2004 Busan I’Cons) Chris Marsden (2004 Busan I’Cons) Richard Offiong (2005 Chunnam Dragons) Derek Asamoah (2011–2012 Pohang ...
... functions, all data structures, including cons cells, are not fundamentally necessary to the language, since all data structures can be implemented using ... For example, in Scheme (define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p))) (define (cdr z) (z (lambda (p q) q))) The above code re ... is impractical because it renders cons cells indistinguishable from any other Scheme procedure, as well as introducing unnecessary computational inefficiencies ...