I'm doing a tut on lisp http://common-lisp.net/language.html#sec-1 and am wondering how would this function be written:
(my-floor 1.3)
=> 1 0.3
I'm doing a tut on lisp http://common-lisp.net/language.html#sec-1 and am wondering how would this function be written:
(my-floor 1.3)
=> 1 0.3
Use values
:
(defun foo (x y)
(values x y (+ x y) (cons x y)))
Try the function:
> (foo 2 pi)
2 ;
3.1415926535897932385L0 ;
5.1415926535897932383L0 ;
(2 . 3.1415926535897932385L0)
Use the returned values with multiple-value-bind
:
(multiple-value-bind (a b sum pair) (foo 1 2)
(list a b sum pair))
==> (1 2 3 (1 . 2))
or (setf values)
.
See also values function in Common Lisp.