在Lisp中,如何使用floor函数返回的第二个值? [英] In lisp, how do I use the second value that the floor function returns?

查看:102
本文介绍了在Lisp中,如何使用floor函数返回的第二个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做时(4楼3楼),我得到了

When I do (floor 4 3) I got

1
1/3

但是我该如何使用1/3?

But how do I use that 1/3?

推荐答案

例如,您可以使用multiple-value-bind将其绑定到变量.

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))

如果您仅对一个非主值感兴趣,另一种可能性是nth-value.

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)))

有关参考,请参见 Hyperspec .

这篇关于在Lisp中,如何使用floor函数返回的第二个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆