Encyclopedia > Cons

  Article Content

Cons

In computer programming, cons is a function used by programming languages that are dialects of Lisp. It is the inverse of car and cdr, and is used to construct lists.

For example, to construct the list (apples oranges pears bananas) from the three-element list (oranges pears bananas), you would use cons as follows:

 (cons 'apples '(oranges pears bananas))

The function cons always adds the new element to the beginning of the list. It must always have a list to start with, and fortunately, this can be the empty list. As an example, to construct the list (peaches), you would code:

 (cons 'peaches ())



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
242

... 210s 220s 230s - 240s - 250s 260s 270s 280s 290s Years: 237 238 239 240 241 - 242 - 243 244 245 246 247 Events Patriarch Titus[?] succeeds Patriarch Eugenius I[?] ...

 
 
 
This page was created in 20.4 ms