Common Lisp - Syntax

Syntax

Common Lisp is a dialect of Lisp; it uses S-expressions to denote both code and data structure. Function and macro calls are written as lists, with the name of the function first, as in these examples:

(+ 2 2) ; adds 2 and 2, yielding 4. (defvar *x*) ; Ensures that a variable *x* exists, ; without giving it a value. The asterisks are part of ; the name. 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 ;; Define a function that squares a number: (defun square (x) (* x x)) ;; Execute the function: (square 3) ; Returns 9 ;; 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

Read more about this topic:  Common Lisp