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
Lisp (programming language)
(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!
====List-processing procedures==== Lisp provides many built-in procedures for accessing and controlling lists. Lists can be created directly with the {{Lisp2|list}} procedure, which takes any number of arguments, and returns the list of these arguments. <syntaxhighlight lang="Lisp"> (list 1 2 'a 3) ;Output: (1 2 a 3) </syntaxhighlight> <syntaxhighlight lang="Lisp"> (list 1 '(2 3) 4) ;Output: (1 (2 3) 4) </syntaxhighlight> Because of the way that lists are constructed from [[cons pair]]s, the {{Lisp2|cons}} procedure can be used to add an element to the front of a list. The {{Lisp2|cons}} procedure is asymmetric in how it handles list arguments, because of how lists are constructed. <syntaxhighlight lang="Lisp"> (cons 1 '(2 3)) ;Output: (1 2 3) </syntaxhighlight> <syntaxhighlight lang="Lisp"> (cons '(1 2) '(3 4)) ;Output: ((1 2) 3 4) </syntaxhighlight> The {{Lisp2|append}} procedure appends two (or more) lists to one another. Because Lisp lists are linked lists, appending two lists has [[Big O notation|asymptotic time complexity]] <math>O(n)</math> <syntaxhighlight lang="Lisp"> (append '(1 2) '(3 4)) ;Output: (1 2 3 4) </syntaxhighlight> <syntaxhighlight lang="Lisp"> (append '(1 2 3) '() '(a) '(5 6)) ;Output: (1 2 3 a 5 6) </syntaxhighlight>
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)