开发者

In lisp, how do I use the second value that the floor function returns?

开发者 https://www.devze.com 2023-03-26 13:37 出处:网络
When I do (floor 4 3) I got 1 1/3 But h开发者_C百科ow do I use that 1/3?You can for instance bind it to a variable using multiple-value-bind.

When I do (floor 4 3) I got

1
1/3

But h开发者_C百科ow do I use that 1/3?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消