OK, so maybe being home with the flu isn't the best time to go back to
Lisp. But why doesn't this work?
(defun grand-sum (data sum)
(cond ((numberp data)
(+ sum data))
((null data)
sum)
((not (listp data))
sum)
(grand-sum (cdr data) (grand-sum (car data) sum))))
;;; Warning: Symbol GRAND-SUM assumed special
GRAND-SUM
(grand-sum 9 0)
9
(grand-sum '(9) 0)
;;; An error occurred in function GRAND-SUM:
;;; Error: The variable GRAND-SUM is unbound
Why is GRAND-SUM a variable, rather than my function?
········@pobox.com wrote:
> OK, so maybe being home with the flu isn't the best time to go back to
> Lisp. But why doesn't this work?
>
> (defun grand-sum (data sum)
> (cond ((numberp data)
> (+ sum data))
> ((null data)
> sum)
> ((not (listp data))
> sum)
> (grand-sum (cdr data) (grand-sum (car data) sum))))
> ;;; Warning: Symbol GRAND-SUM assumed special
> GRAND-SUM
> (grand-sum 9 0)
> 9
> (grand-sum '(9) 0)
> ;;; An error occurred in function GRAND-SUM:
> ;;; Error: The variable GRAND-SUM is unbound
>
> Why is GRAND-SUM a variable, rather than my function?
Hi,
Because that last line should look a little more like:
(t
(grand-sum (cdr data) (grand-sum (car data) sum)))))
than:
(grand-sum (cdr data) (grand-sum (car data) sum))))
Due to the way COND is evaluated, it expects GRAND-SUM to be a
variable.
Tayssir
On 4 Feb 2006 18:28:23 -0800, ········@pobox.com wrote:
>OK, so maybe being home with the flu isn't the best time to go back to
>Lisp. But why doesn't this work?
>
>(defun grand-sum (data sum)
> (cond ((numberp data)
> (+ sum data))
> ((null data)
> sum)
> ((not (listp data))
> sum)
> (grand-sum (cdr data) (grand-sum (car data) sum))))
>;;; Warning: Symbol GRAND-SUM assumed special
>GRAND-SUM
>(grand-sum 9 0)
>9
>(grand-sum '(9) 0)
>;;; An error occurred in function GRAND-SUM:
>;;; Error: The variable GRAND-SUM is unbound
>
>Why is GRAND-SUM a variable, rather than my function?
Because it's the start of your last cond clause.