Multiple Return Values in Lisp
Lisp has built-in support for multiple return values. This feature is often used in idiomatic Lisp, for example to return both result and error values from a function.
The (values 3 7)
in the vals
function shows that the function returns 2 integers.
In the main
function:
Here we use the 2 different return values from the call with multiple-value-bind
, which is Lisp’s way of handling multiple assignment.
If you only want a subset of the returned values, you can use the underscore _
as a placeholder and declare it as ignored. This is similar to using the blank identifier in other languages.
To run the program:
Returning multiple values is a powerful feature in Lisp that allows for expressive and efficient code. We’ll explore more Lisp features in the upcoming examples.