From: Mike Chu
Subject: HELP! PLEASE!!
Date: 
Message-ID: <36CCF832.1F20F9FC@hotmail.com>
Excuse me, could anyone tell me that what the line "((equal (atom (car
x)) nil

(first-atom (car x)))
is doing for the following function, which returns the first atom of the
list, eq.
(a b c) => a,   and thanks for the valuable opinion!!!

(defun first-atom (x)
    (cond
       ((equal (atom (car x)) nil
                    (first-atom (car x)))
       (t (car x))))

From: Chris Croft-White
Subject: Re: HELP! PLEASE!!
Date: 
Message-ID: <36CD78D3.1B5B75A1@cam.ac.uk>
Think about nested lists!!

Chris Croft-White

Mike Chu wrote:

> Excuse me, could anyone tell me that what the line "((equal (atom (car
> x)) nil
>
> (first-atom (car x)))
> is doing for the following function, which returns the first atom of the
> list, eq.
> (a b c) => a,   and thanks for the valuable opinion!!!
>
> (defun first-atom (x)
>     (cond
>        ((equal (atom (car x)) nil
>                     (first-atom (car x)))
>        (t (car x))))
From: Johan Kullstam
Subject: Re: HELP! PLEASE!!
Date: 
Message-ID: <u7lte1n91.fsf@res.raytheon.com>
Mike Chu <······@hotmail.com> writes:

> Excuse me, could anyone tell me that what the line "((equal (atom (car
> x)) nil
>
> (first-atom (car x)))
> is doing for the following function, which returns the first atom of the
> list, eq.
> (a b c) => a,   and thanks for the valuable opinion!!!
> 
> (defun first-atom (x)
>     (cond
>        ((equal (atom (car x)) nil
>                     (first-atom (car x)))
>        (t (car x))))

break this down into its parts

car - get the first item in a list

atom - returns nil for lists and t for everything else

equal nil - returns nil for t and t for nil - basically a `not'


(equal (atom w) nil) is true whenever w is not an atom, i.e., w is a
list!

if w is a list, strip away a layer of parentheses (using car) and try
again.

even though it seems you are restricted to a rather spartan form of
lisp, you can use the full power of the language/environment for
debugging.  `trace' can help a lot when dealing with recursive
functions.  trace will show each call to the function and display the
arguments passed.

try

> (trace first-atom)

> (first-atom '(((1 2) (92 100)) 3 4))

see what you get.

hope this helps.

-- 
johan kullstam