Common Lisp: This is not a number NIL and &rest parameters
Asked Answered
E

1

-1

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)))
Echidna answered 26/4, 2014 at 4:47 Comment(0)
A
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)))
Allotropy answered 26/4, 2014 at 6:22 Comment(3)
(second args) can be nil...can u help me with a solution, to squash that warning....thanks for joining in btw:)Echidna
Perhaps something like the above.Allotropy
Great, that worked like a charm, great way to think outside of the boxEchidna

© 2022 - 2024 — McMap. All rights reserved.