我正在处理一些调用 ADJUST-ARRAY 的代码。我从 Lisp 解释器 (CMUCL) 收到一条警告消息,指出不应忽略 ADJUST-ARRAY 的返回值。
如果我没记错的话,在我正在处理的代码中,ADJUST-ARRAY 修改了它的参数。所以没有必要对返回值做任何事情。在 Common Lisp 中是否有指定的方法来忽略返回值?当然,我可以将返回值赋给某个变量,然后忽略该变量。但这感觉很笨拙。
我还可以将返回值分配给 ADJUST-ARRAY 参数,例如:
(setq my-array (adjust-array my-array ...))
但这似乎表明我不确定 ADJUST-ARRAY 是否会就地修改 MY-ARRAY。
欢迎任何建议,在此先感谢。
最佳答案
你是对的。作为the documentation状态:
The result is an array of the same type and rank as array, that is either the modified array, or a newly created array to which array can be displaced, and that has the given new-dimensions.
如果结果是新创建的数组,那么函数当然会对参数没有影响。
Common Lisp 几乎总是要求您使用返回值而不是旧的绑定(bind),以便拥有可移植的代码。
关于lisp - 如何忽略 Common Lisp 中的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48896161/