From: ········@pobox.com
Subject: Fevered re-newbie
Date: 
Message-ID: <1139106503.050573.253470@o13g2000cwo.googlegroups.com>
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?

From: Tayssir John Gabbour
Subject: Re: Fevered re-newbie
Date: 
Message-ID: <1139106895.530500.177180@f14g2000cwb.googlegroups.com>
········@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
From: ········@pobox.com
Subject: Re: Fevered re-newbie
Date: 
Message-ID: <1139110051.169407.37490@f14g2000cwb.googlegroups.com>
Right, thank you (and JP Masser below). Too many years (albeit ending
several years ago) using @If in Notes, which takes an odd number of
arguments.
From: JP Massar
Subject: Re: Fevered re-newbie
Date: 
Message-ID: <evqau159v0b470g89rsre92e2o8val5rvn@4ax.com>
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.