8

When I do (floor 4 3) I got

1
1/3

But how do I use that 1/3?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
h__
  • 865
  • 1
  • 11
  • 19

1 Answers1

21

You can for instance bind it to a variable using multiple-value-bind.

(multiple-value-bind (quot rem)
    (floor 4 3)
  (format t "The remainder is ~f~%" rem))

Another possibility, if you're only interested in one non-primary value, is nth-value.

(format t "The remainder is also ~f~%" (nth-value 1 (floor 4 3)))

For reference, see the Hyperspec.

Peder Klingenberg
  • 37,937
  • 1
  • 20
  • 23
  • 4
    If you are _only_ interested in the remainder, you can use `rem` or `mod` (http://www.lispworks.com/documentation/HyperSpec/Body/f_mod_r.htm). – Svante Aug 08 '11 at 19:56
  • 3
    @Svante Good point, thanks. I was assuming the question was more about the general behaviour of multiple values, but that is not obvious from the original question. hyh: If your problem was indeed the concrete one of finding the remainder from some calculation, use Svante's suggestions, it will make your code better by clearly stating your intention. – Peder Klingenberg Aug 08 '11 at 20:08
  • 1
    thanks for the hyperspec link I had no idea lisp just discards the second value. – jjj Apr 21 '20 at 08:29