Let’s try some basic expression in the REPL:
CL-USER> (+ 1 2 3)
6
CL-USER> (- 3 1 1)
1
CL-USER> (- 3)
-3
CL-USER> (+ 5.3 (- 3 2) (* 2 2))
10.3
CL-USER> (concatenate 'string "Hello, " "World!")
"Hello, World!"
CL-USER>
The basic building block of a Common Lisp program is the form. In these examples we have functions forms, that is expressions, written as list, in which the first element is an operator (or function) and the rest of the elements are the operands (this is called “Prefix Notation”, or “Polish Notation”). Writing forms in the REPL causes their evaluation. In the examples you can see simple expressions whose arguments are constant numbers, strings and symbols (in the case of 'string
, which is the name of a type). You can also see that arithmetic operators can take any number of arguments.
It is important to note that parentheses are an integral part of the syntax, and cannot be used freely as in other programming languages. For instance the following is an error:
(+ 5 ((+ 2 4)))
> Error: Car of ((+ 2 4)) is not a function name or lambda-expression. ...
In Common Lisp forms can also be data, symbols, macro forms, special forms and lambda forms. They can be written to be evaluated, returning zero, one, or more values, or can be given in input to a macro, that transform them in other forms.