4

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
4
  • 1
    The link you reference tells you ... You just use values. Commented Jul 18, 2014 at 6:16
  • 1
    rosettacode.org/wiki/Return_multiple_values#Common_Lisp Commented Jul 18, 2014 at 6:18
  • 1
    This question appears to be off-topic because it is answered just several paragraphs down in the document linked in the question. Commented Jul 18, 2014 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. Commented Jul 19, 2014 at 4:24

1 Answer 1

13

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.

Sign up to request clarification or add additional context in comments.

2 Comments

How does one access these values in code? Is that a list of values?
Much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.