在lisp中,如何使用floor函数返回的第二个值?
当我这样做的时候(4层3层),我得到了在lisp中,如何使用floor函数返回的第二个值?,lisp,common-lisp,Lisp,Common Lisp,当我这样做的时候(4层3层),我得到了 但是如何使用1/3呢?例如,您可以使用多值绑定将其绑定到变量 (multiple-value-bind (quot rem) (floor 4 3) (format t "The remainder is ~f~%" rem)) 如果您只对一个非主要值感兴趣,另一种可能是n值 (format t "The remainder is also ~f~%" (nth-value 1 (floor 4 3))) 如需参考,请参阅。如果您只对剩余部
但是如何使用1/3呢?例如,您可以使用
多值绑定将其绑定到变量
(multiple-value-bind (quot rem)
(floor 4 3)
(format t "The remainder is ~f~%" rem))
如果您只对一个非主要值感兴趣,另一种可能是n值
(format t "The remainder is also ~f~%" (nth-value 1 (floor 4 3)))
如需参考,请参阅。如果您只对剩余部分感兴趣,可以使用rem
或mod
()。@Svante很好,谢谢。我假设问题更多的是关于多重价值观的一般行为,但从最初的问题来看,这并不明显。hyh:如果您的问题确实是从某些计算中找到余数的具体问题,请使用Svante的建议,通过明确说明您的意图,它将使您的代码变得更好。感谢hyperspec链接,我不知道lisp只是丢弃了第二个值。
(format t "The remainder is also ~f~%" (nth-value 1 (floor 4 3)))