[英]How to ignore a return value in Common Lisp
I'm working with some code which calls ADJUST-ARRAY. 我正在处理一些称为ADJUST-ARRAY的代码。 I am getting a warning message from the Lisp interpreter (CMUCL) that the return value of ADJUST-ARRAY should not be ignored.
我收到来自Lisp解释器(CMUCL)的警告消息,不应忽略ADJUST-ARRAY的返回值。
In the code I am working on, ADJUST-ARRAY modifies its argument in place, if I am not mistaken. 在我正在处理的代码中,如果我没有记错的话,ADJUST-ARRAY会修改其参数。 So it's not necessary to do anything with the return value.
因此,无需对返回值做任何事情。 Is there a designated way to ignore a return value in Common Lisp?
是否有一种指定的方法可以忽略Common Lisp中的返回值? Of course, I could assign the return value to some variable, and then ignore the variable.
当然,我可以将返回值分配给某个变量,然后忽略该变量。 But that feels clumsy.
但这感觉很笨拙。
I could also assign the return value to the ADJUST-ARRAY argument, something like: 我还可以将返回值分配给ADJUST-ARRAY参数,例如:
(setq my-array (adjust-array my-array ...))
but that seems to suggest that I'm not sure if ADJUST-ARRAY will modify MY-ARRAY in place. 但这似乎表明我不确定ADJUST-ARRAY是否会就地修改MY-ARRAY。
Any advice is welcome, thanks in advance. 欢迎任何建议,谢谢。
You are correct. 你是对的。 As the documentation states:
如文档所述:
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.
结果是与数组具有相同类型和级别的数组,它要么是修改后的数组,要么是可以将数组移位到的新创建的数组 ,并且具有给定的新维度。
If the result is a newly created array then of course the function would have had no effect on the argument. 如果结果是一个新创建的数组,那么该函数当然不会对参数产生影响 。
Common Lisp almost always require you to use the returned value rather than old bindings in order to have portable code. 为了拥有可移植的代码,Common Lisp几乎总是要求您使用返回值而不是旧的绑定。
The specification of adjust-array
is that the adjusted array is the one returned. adjust-array
的规范是adjust-array
后的数组是返回的数组。
What you can expect of the argument array afterwards to be is a bit complicated and may differ between implementations in some cases. 之后,您对参数数组的期望可能会有些复杂,并且在某些情况下可能会因实现而有所不同。
Just use the one returned. 只需使用返回的那个。 You might use
setf
to modify or let
to create a binding. 您可以使用
setf
修改或let
创建绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.