Common Lisp:这不是数字NIL和&rest参数 [英] Common Lisp: This is not a number NIL and &rest parameters

查看:108
本文介绍了Common Lisp:这不是数字NIL和&rest参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此行((pointerp(第一个参数))(mem-aref(%vector-float-to-c-array(第一个参数)):float(第二个参数)))在下面的代码中,(第二个参数)编译时显示警告这不是数字NIL 。该函数有效,但是我如何仅使用Lisp以隐含的独立方式摆脱此警告。解决方案必须非常快。该代码花了很长时间才能正确执行,并且运行良好,因此我无法真正更改其操作。您不认识的功能实际上并没有关系,要发出警告...请提前感谢您。

On this line ((pointerp (first args)) (mem-aref (%vector-float-to-c-array (first args)) :float (second args))) in the below code the (second args) compiles with the warning This is not a number NIL. The function works but how do I get rid of this warning in an implimentation independent way using just Lisp. The solution would need to be really fast. The code took a long time to get to right and runs great so I can't really change the operation of it. the functions you don't recognize don't really matter as far getting warning to go away...Thank you in advance for any help.

(defun vector-float (&rest args)
  (cond ((eq (first args) nil) (return-from vector-float (%vector-float)))
    ((listp (first args))
     (c-arr-to-vector-float (first args)))
    ((symbolp (cadr args)) (%vector-float-size (first args)))
    ((pointerp (first args)) (mem-aref (%vector-float-to-c-array (first args)) :float (second args)))
    (t nil)))


推荐答案

如果(second args) NIL ,那么 args 都没有 second 或其 NIL 。但是,内存区域的第三个参数必须是数字,因为它是一个索引。这就是问题所在。

If (second args) is NIL then either args has no second or its second is NIL. However, the third argument to mem-aref must be a number since it is an index. Therein lies the problem.

如果程序中的(第二个参数)允许为 NIL (或不存在),则必须测试这种可能性,并避免将 NIL 传递给 mem-aref (也许通过省略该可选参数)。如果不允许(第二个参数) NIL ,则该错误位于某处

If in your program (second args) is allowed to be NIL (or to not exist), then you'll have to test for that possibility and avoid passing NIL to mem-aref (maybe by leaving out that optional argument). If (second args) is not allowed to be NIL, then the bug is somewhere else in your program.

例如(未测试),

(defun vector-float (&rest args)
    (cond
        ((null (first args))
            (return-from vector-float (%vector-float)))
        ((listp (first args))
            (c-arr-to-vector-float (first args)))
        ((symbolp (second args))
            (%vector-float-size (first args)))
        ((pointerp (first args))
            (if (null (second args))
                (mem-aref (%vector-float-to-c-array (first args)) :float)
                (mem-aref (%vector-float-to-c-array (first args)) :float (second args))))
        (t nil)))

这篇关于Common Lisp:这不是数字NIL和&rest参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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