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
Common Lisp
(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!
==Syntax== Common Lisp is a dialect of Lisp. It uses [[S-expression]]s to denote both code and data structure. Function calls, macro forms and special forms are written as lists, with the name of the operator first, as in these examples: <syntaxhighlight lang="lisp"> (+ 2 2) ; adds 2 and 2, yielding 4. The function's name is '+'. Lisp has no operators as such. </syntaxhighlight> <syntaxhighlight lang="lisp"> (defvar *x*) ; Ensures that a variable *x* exists, ; without giving it a value. The asterisks are part of ; the name, by convention denoting a special (global) variable. ; The symbol *x* is also hereby endowed with the property that ; subsequent bindings of it are dynamic, rather than lexical. (setf *x* 42.1) ; Sets the variable *x* to the floating-point value 42.1 </syntaxhighlight> <syntaxhighlight lang="lisp"> ;; Define a function that squares a number: (defun square (x) (* x x)) </syntaxhighlight> <syntaxhighlight lang="lisp"> ;; Execute the function: (square 3) ; Returns 9 </syntaxhighlight> <!-- I truncated this a bit; in smaller browsers, it runs off the side--> <syntaxhighlight lang="lisp"> ;; The 'let' construct creates a scope for local variables. Here ;; the variable 'a' is bound to 6 and the variable 'b' is bound ;; to 4. Inside the 'let' is a 'body', where the last computed value is returned. ;; Here the result of adding a and b is returned from the 'let' expression. ;; The variables a and b have lexical scope, unless the symbols have been ;; marked as special variables (for instance by a prior DEFVAR). (let ((a 6) (b 4)) (+ a b)) ; returns 10 </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)