-1

((pointerp (first args)) (mem-aref (%vector-float-to-c-array (first args)) :float (second args)))在下面代码的这一行中,(second args)编译时带有警告This is not a number NIL。该功能有效,但我如何仅使用 Lisp 以独立于实现的方式摆脱此警告。解决方案需要非常快。该代码需要很长时间才能正确运行并且运行良好,因此我无法真正更改它的操作。您不认识的功能与警告消失无关紧要……提前感谢您的帮助。

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

1 回答 1

1

If (second args)is NILthen 要么argshas nosecond要么secondis NIL。但是,第三个参数mem-aref必须是一个数字,因为它是一个索引。问题就在于此。

如果在您的程序(second args)中允许存在NIL(或不存在),那么您必须测试这种可能性并避免传递NILmem-aref(可能通过省略该可选参数)。如果不允许(second args)则该错误在您程序中的其他位置。NIL

例如(未经测试),

(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)))
于 2014-04-26T06:22:32.980 回答