(print "Hello World!") ;;Hello World!
Note: Common Lisp ignores the comment operator (;) and everything after it on the line
(let ( {symbol | (symbol form)}*)Establishes each symbol as the name of a variable. The scope of each of these variables is limited to the let form, unless it is named in the declaration, in which case that variable has dynamic scope. If a form is given with a symbol, the value of the form becomes the initial value of the variable named by the symbol. These forms are evaluated in order, but the assignment of their values to their variables is done in parallel. A variable without an initialization form is initialized to NIL. Variables named in the declaration that are not established by this let form are special variables established elsewhere that will be used in the forms of this let. After the establishment and initialization of all the variables, the forms are evaluated in order, and the value of the last one becomes the value of the let form.special form
[(declare (special variables))]
forms)
(let* ( {symbol | (symbol form)}*) special form
[(declare (special variables))]
forms)
(psetf {place form}*) ;;macroJust like setf, except evaluates all the forms first, then assigns the values to the corresponding places in parallel. Returns NIL.
(psetq {symbol form}*) ;;macro
(set symbol form) ;;function
(setf {place form}*) ;;macro
(setq {symbol form}*) ;;special form
(prog1 forms) ;;macroThe forms are evaluated in order and the value of the first is returned.
(prog2 forms) ;;macro
(progn [forms]) ;;special form
(return [form]) ;;macro
(case form ;;macro
((objects1) forms1)
...
((objectsn) formsn))
(cond (test1 [forms1]) ... (testn [formsn])) ;;special form
(if test then [else]) ;;special formIf test evaluates to True, evaluates and returns the value of then; otherwise, if else is present, evaluates and returns the value of else; otherwise, returns NIL.
(typecase form (type1 forms1) ... (typen formsn)) ;;macroform is evaluated. formsi are evaluated for the lowest i for which the value of form is of type typei and the value of the last formsi is returned as the value of the call to typecase. The typei are not evaluated. If the value of form is not any of the typei, NIL is returned unless either t or otherwise appears instead of (typen), in which case the formsn are evaluated and the value of the last formsn is returned.
(unless test forms) ;;macroEvaluates test. If the value is NIL, evaluates the forms in order and returns the value of the last one. Otherwise, does not evaluate the forms and returns NIL.
(when test forms) ;;macroEvaluates test. If the value is NIL, does not evaluate the forms and returns NIL. Otherwise, evaluates the forms in order and returns the value of the last one.
(dolist (symbol list-form [result-form]) statements) ;;macro
(dotimes (symbol form resultform) statements) ;;macro
(loop statements) ;;macro
(function fn) ;;special formIf fn is a symbol, returns the function named by that symbol. If fn is a lambda expression, returns the functional closure of that expression. An alternate printed representation of (function fn) is #’fn.
(apply function [forms1] ([forms2])) ;;functionA list of forms1 is appended to the list of forms2, and the function is applied to that list of argument forms. If a symbol is given instead of a function, the function the symbol names is used.
(funcall function [forms]) functionApplies the function to the argument forms. function may only be a function; it can’t be a macro or a special form.
(mapc function lists) ;;function
(mapcan function lists) ;;functionfunction must return a list, and there must be the same number of lists as the number of arguments function takes. function is applied to the first member of each of the lists, the second member, and so on, until the shortest list is exhausted. The nconc of the values is returned.
(mapcar function lists) ;;functionThere must be the same number of lists as the number of arguments function takes. function is applied to the first member of each of the lists, the second member, and so on, until the shortest list is exhausted. A list of the values is returned.
(assert assertion [(variables1) [string variables2]]) ;;macroIf the form assertion evaluates to True, returns NIL. Otherwise, an error is forced and Lisp prints an error message and gives the user the choice of aborting the computation or replacing the current values of the variables listed as variables1. If the user chooses to replace the current values, the assert form is retried with the new values. The error message is formed, in part, by applying format to string and variables2.
(check-type variable type-specifier) ;;macro
(deftype symbol () doc-string ’(satisfies function)) ;;macro
(time form) ;;macroEvaluates form and prints how long it took to do the evaluation. Returns the value of form.
(trace [function-names]) ;;macroTurns on tracing of the specified functions (function-names are not evaluated.) With no arguments, returns a list of all functions being traced.
(untrace [function-names]) ;;macroTurns off tracing of the specified functions (function-names are not evaluated.) With no arguments, turns off all tracing.
(format stream control-string arguments) ;;function
~% Causes a newline to be printed. ~& Causes a newline to be printed unless printing is already at the beginning of a new line ~~ Causes the character ~ to be printed. ~#\newline A ~ appearing in the control-string right before the end of a line causes the end-of-line and all subsequent blanks to be ignored. It is a way of splitting a long control-string over several lines.
~a or ~A Consumes one argument and prints it without escape characters, as princ would ~s or ~S Consumes one argument and prints it with escape characters, as prin1 would ~{str~} Consumes one argument, which must be a list, and prints the members of the list according to the control string str as if they were arguments to an embedded call of format. If str doesn’t consume all the members of the list, it is used again on the next group, and so on. ~#[str1~:;str2~] Uses the control string str1 if there is no argument left or the control string str2 if there is any argument left. If this directive is embedded in the ~ {str ~ } directive, the notion of “argument” is replaced by “member” of the list.
(fresh-line [stream]) ;;functionOutputs a newline to stream, which defaults to standard output and returns T, but only if output is not already positioned at the beginning of a new line. In that case, it does nothing and returns NIL.
(pprint object [stream]) ;;functionPrints a newline and then prints the object using escape characters as appropriate and in a “pretty” indented format. Returns no value. Printing is done into stream, which defaults to the standard output.
(prin1 object [stream]) ;;functionPrints the object using escape characters as appropriate. Returns object. Printing is done into stream, which defaults to the standard output.
(princ object [stream]) ;;functionPrints the object without using escape characters. Returns object. Printing is done into stream, which defaults to the standard output.
(print object [stream]) ;;functionPrints the object using escape characters as appropriate, preceded by a newline and followed by a space. Returns object. Printing is done into stream, which defaults to the standard output.
(read [stream]) ;;functionReads one S-expression from the input stream, which defaults to standard input, and returns the object represented by that S-expression.
(terpri [stream]) ;;functionOutputs a newline to stream, which defaults to standard output and returns NIL.
(make-array n) ;;functionCreates and returns an array of n elements, indexed from 0 to n − 1. Each element can be any Common Lisp object.
(aref array i) ;;functionReturns the ith element of array. i must be a nonnegative integer less than the number of elements of array. Indexing is zero-based. That is, the first element of array is retrieved with (aref array 0). Forms a generalized variable recognizable by setf.
Common Lisp is used in many successful commercial applications, the most famous (no doubt due to Paul Graham's promotion) was the Yahoo! Store web-commerce site, which later was rewritten in C++ and Perl.Other notable examples include:
As well, Common Lisp is used by many government and non-profit institutions. Examples of its use in NASA include: