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
zcaudate
  • 13,998
  • 7
  • 64
  • 124
  • 1
    The link you reference tells you ... You just use values. – okaram Jul 18 '14 at 06:16
  • 1
    http://rosettacode.org/wiki/Return_multiple_values#Common_Lisp – didierc Jul 18 '14 at 06:18
  • 1
    This question appears to be off-topic because it is answered just several paragraphs down in the document linked in the question. – Joshua Taylor Jul 18 '14 at 20:09
  • 1
    I'm a little bit surprised at the downvotes here. its always easy when you have the answer and know where to look. Yes I know its an obvious question but sometimes its the obvious ones that need to be addressed first before any learning can be done. – zcaudate Jul 19 '14 at 04:24

1 Answers1

12

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.

sds
  • 58,617
  • 29
  • 161
  • 278