From: Chia-Lin Wang
Subject: A-list ??
Date: 
Message-ID: <366D731B.C5EE2F25@is.nyu.edu>
I wrote a program using A-list.

         (set q father '((GEORGE . FRED)
                                 (FRED . ARTHUR)
                                  (VIRGINIA . ARTHUR))


          (defun ANCESTOR (person)
                  (if (null person)
                        (return-from ANCESTOR)
                   (progn (print
person)
; if I used (list person), I got 'nil'
                               (ANCESTORS (cdr (assoc person
FATHER))))))          ; i don't what might be the problem

; if anyone knows, please tell me
            (ANCESTOR
'GEORGE)
; t hanks



                  ; the result is GEORGE
                                        FRED
                                        ARTHUR
                                         NIL
              How can I get a result like (GEORGE) (FRED) (ARTHUR) (NIL)
?

From: Barry Margolin
Subject: Re: A-list ??
Date: 
Message-ID: <1Dgb2.65$g34.4617@burlma1-snr1.gtei.net>
In article <·················@is.nyu.edu>,
Chia-Lin Wang  <······@is.nyu.edu> wrote:
>I wrote a program using A-list.
>
>         (set q father '((GEORGE . FRED)
>                                 (FRED . ARTHUR)
>                                  (VIRGINIA . ARTHUR))
>
>
>          (defun ANCESTOR (person)
>                  (if (null person)
>                        (return-from ANCESTOR)
>                   (progn (print
>person)
>; if I used (list person), I got 'nil'

Because the keys in your a-list are symbols, not lists.  Also, even if they
were lists, (list person) would create a fresh list, which wouldn't be EQL
to the ones in the a-list.

>                               (ANCESTORS (cdr (assoc person
>FATHER))))))          ; i don't what might be the problem

Shouldn't this call ANCESTOR recursively?  You don't have an ANCESTORS
function.

>; if anyone knows, please tell me
>            (ANCESTOR
>'GEORGE)
>; t hanks
>
>
>
>                  ; the result is GEORGE
>                                        FRED
>                                        ARTHUR
>                                         NIL
>              How can I get a result like (GEORGE) (FRED) (ARTHUR) (NIL)
>?

(prin1 (list person)) instead of (print person) and it will wrap each one
up in a list and not put a newline before each one.  I'm not sure why you
would want this, though.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.
From: Steve Gonedes
Subject: Re: A-list ??
Date: 
Message-ID: <m2u2z6yzo4.fsf@KludgeUnix.com>
Chia-Lin Wang <······@is.nyu.edu> writes:

< 
< I wrote a program using A-list.
< 
<          (set q father '((GEORGE . FRED)
<                                  (FRED . ARTHUR)
<                                   (VIRGINIA . ARTHUR))
< 
< 
<           (defun ANCESTOR (person)
<                   (if (null person)
<                         (return-from ANCESTOR)
<                    (progn (print
< person)
< ; if I used (list person), I got 'nil'
<                                (ANCESTORS (cdr (assoc person
< FATHER))))))          ; i don't what might be the problem
< 
< ; if anyone knows, please tell me
<             (ANCESTOR
< 'GEORGE)
< ; t hanks
< 
< 
< 
<                   ; the result is GEORGE
<                                         FRED
<                                         ARTHUR
<                                          NIL
<               How can I get a result like (GEORGE) (FRED) (ARTHUR) (NIL)
< ?

(defvar *ancestors*
     '((GEORGE . FRED)
       (FRED . ARTHUR) (VIRGINIA . ARTHUR)))

(defun find-ancestor (person ancestors)
  (rest (assoc person ancestors)))

(defun make-family-tree (name ancestors)
  (if (null name) name
      (cons (list name)
            (make-family-tree (find-ancestor name ancestors) ancestors))))

(make-family-tree 'george *ancestors*)
=> ((george)
    (fred)
    (arthur))

Dunno how to get the (nil) in the result though.