1 | initial version |
To generate a return statement in Common Lisp, you can use the built-in function return-from
.
The syntax for return-from
is as follows:
return-from tagname value
Here, tagname
is an identifier that represents the block of code to which the return statement applies, and value
is the optional value to be returned.
For example, suppose you have a function square-root
that computes the square root of a number. You could use return-from
to exit the function early and return a value if an error condition occurs:
(defun square-root (x)
(if (< x 0)
(return-from square-root nil)
(sqrt x)))
In this example, if x
is negative, the if
statement returns nil
by calling return-from
with the identifier square-root
.