Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Cons
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Function and primitive data structure in Lisp and other functional programming languages}} {{about|the Lisp programming function}} {{more citations needed|date=January 2019}} {{lowercase title}} In [[computer programming]], '''{{lisp2|cons}}''' ({{IPAc-en|Λ|k|Ι|n|z}} or {{IPAc-en|Λ|k|Ι|n|s}}) is a fundamental [[subroutine|function]] in most dialects of the [[Lisp (programming language)|Lisp]] programming language. {{lisp2|cons}} '''''cons'''tructs'' memory objects which hold two values or pointers to two values. These objects are referred to as (cons) cells, conses, non-atomic [[s-expressions]] ("NATSes"), or (cons) [[ordered pair|pairs]]. In Lisp jargon, the expression "to cons ''x'' onto ''y''" means to construct a new object with <code>(cons ''x'' ''y'')</code>. The resulting pair has a left half, referred to as the {{lisp2|car}} (the first element, or ''[[CAR and CDR|'''c'''ontents of the '''a'''ddress part of '''r'''egister]]''), and a right half, referred to as the {{lisp2|cdr}} (the second element, or ''[[CAR and CDR|'''c'''ontents of the '''d'''ecrement part of '''r'''egister]]''). It is loosely related to the [[object-oriented programming|object-oriented]] notion of a [[constructor (computer science)|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 [[Operator (programming)|operators]] that have a similar purpose, especially in the context of list processing, are pronounced "cons". (A good example is the <code>::</code> operator in [[ML programming language|ML]], [[Scala (programming language)|Scala]], [[F Sharp (programming language)|F#]], [[Lean (proof assistant)|Lean]], [[Coq (software)|Coq]], and [[Elm (programming language)|Elm]] or the <code>:</code> operator in [[Haskell (programming language)|Haskell]], which adds an element to the beginning of a list.)
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)