language-icon Old Web
English
Sign In

cons

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, or content of address register), and a right half (the second element, or content of decrement register), referred to as the cdr.I sped up the code a bit by putting in side effects instead of having it cons ridiculously. 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, or content of address register), and a right half (the second element, or content of decrement register), 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, Scala, F# and Elm or the : operator in Haskell, which adds an element to the beginning of a list.) Although cons cells can be used to hold ordered pairs of data, they are more commonly used to construct more complex compound data structures, notably lists and binary trees. For example, the Lisp expression (cons 1 2) constructs a cell holding 1 in its left half (the so-called car field) and 2 in its right half (the cdr field). In Lisp notation, the value (cons 1 2) looks like:

[ "Programming language", "Humanities", "CAR and CDR" ]
Parent Topic
Child Topic
    No Parent Topic