Reputation: 1605
Why does the following code return a nil value instead of 1?
(defun test (list)
(car(list)))
(test '( 1 2 3))
Upvotes: 1
Views: 49
Reputation: 2008
It returns nil
because you're asking what the car
of (list)
is, which is a function invocation of the list
function. Since you're passing the list
function no arguments, it is returning nil
since there is no car
nor cdr
(it's an empty list). The following would produce the desired effect:
(defun test (list)
(car list))
(test '(1 2 3)) ;; now returns 1
Upvotes: 3