问题
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)))
回答1:
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.
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.
E.g. (untested),
(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)))
来源:https://stackoverflow.com/questions/23306757/common-lisp-this-is-not-a-number-nil-and-rest-parameters