Functions

Named Functions

You define functions using the defun macro:

(defunfib(n)"Return the nth Fibonacci number."(if(<n2)n(+(fib(-n1))(fib(-n2)))))

And call them like you call anything else:

CL-USER>(fib30)832040

Anonymous Functions

Application

Functions can be called indirectly using funcall:

CL-USER>(funcall#'fib30)832040

Or with apply:

CL-USER>(apply#'fib(list30))832040

Multiple Return Values

(defunmany(n)(valuesn(*n2)(*n3)))
CL-USER>(multiple-value-list(many2))(246)CL-USER>(nth-value1(many2))4

We can also use multiple-value-bind to assign each return value to a variable:

CL-USER>(multiple-value-bind(firstsecondthird)(many2)(listfirstsecondthird))(246)
close