From: JD
Subject: Lisp Help
Date: 
Message-ID: <KueP8.24760$9b.1161394@typhoon.austin.rr.com>
I'm supposed to be writing a function that receives a key and an association
list of this form:

(setf jane '((jane address
                   (number 1201)
                   (street main)
                   (city san-antonio)
                   (state texas)
                   (zip 75438))
             (parents
                 (father pete)
                 (mother sue))
             (children bob)
             (name jane)
             (weight 120)))
---------------------------

I need to display the data under the key (e.g. (assockey parents jane) would
return ((father pete) (mother sue))

Here is what I have as my function:

(defun assockey (keyinput person)
  (rest (assoc keyinput person)))

but the error message I get is:

Error in EVAL: Symbol has no value: PARENTS

Control Stack Debugger
Eval  #6: PARENTS

They 'keyinput' variable is where I am having my problem.  Any hints on how
to get this?

I'm a beginner with Lisp (as if you couldn't tell), so go easy on me :)

Thanks,

JD

From: Joel Ray Holveck
Subject: Re: Lisp Help
Date: 
Message-ID: <y7cu1o230eb.fsf@sindri.juniper.net>
> I'm supposed to be writing a function that receives a key and an association
> list of this form:
[snip]
> I need to display the data under the key (e.g. (assockey parents jane) would
> return ((father pete) (mother sue))

Is that the exact specification?  Think about what it means to say
  (assockey parents jane)

Lisp will look at the first argument as the name of the function.
When it evaluates the other two arguments, it will take them as
variable names.

We saw you define JANE as a variable, but is PARENTS defined as a
variable?  That's what the message is saying.

I think you may be looking in the wrong place for the problem: you're
looking at your function, but it seems that the problem crops up
before the function gets called.  (If you run "(trace assockey)" this
will become more apparent... at least, calls to ASSOCKEY will be
notably absent.)

So, what's the proper calling sequence?  How do you keep Lisp from
evaluating PARENTS as a variable?  (Hint: You used it in your posting,
to keep a list from being evaluated as a function call.)

Hope this helps,
joelh
From: vsync
Subject: Re: Lisp Help
Date: 
Message-ID: <87sn3ma1lf.fsf@prion.quadium.net>
"JD" <·············@yahoo.com> writes:

> I need to display the data under the key (e.g. (assockey parents jane) would
> return ((father pete) (mother sue))
> 
> Here is what I have as my function:
> 
> (defun assockey (keyinput person)
>   (rest (assoc keyinput person)))
> 
> but the error message I get is:
> 
> Error in EVAL: Symbol has no value: PARENTS

Try quoting the key; in your example, use

  (assockey 'parents jane)

-- 
vsync
http://quadium.net/
(cons (cons (car (cons 'c 'r)) (cdr (cons 'a 'o))) ; Orjner
      (cons (cons (car (cons 'n 'c)) (cdr (cons nil 's))) nil))
From: Matthew Danish
Subject: Re: Lisp Help
Date: 
Message-ID: <20020617015852.E10790@mapcar.org>
Seems like you need to quote the symbol PARENTS so it doesn't get evaluated,
ie. (assockey 'parents jane)

Think of the difference between the symbol JANE and the value it is bound to,
and then consider that PARENTS is not even bound to any value (nor does it
name any variable).

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: JD
Subject: Re: Lisp Help
Date: 
Message-ID: <TVeP8.24766$9b.1166428@typhoon.austin.rr.com>
DOH!

All I had to do was add the ' in front of the middle variable when calling
the function.

JD


"JD" <·············@yahoo.com> wrote in message
···························@typhoon.austin.rr.com...
> I'm supposed to be writing a function that receives a key and an
association
> list of this form:
>
> (setf jane '((jane address
>                    (number 1201)
>                    (street main)
>                    (city san-antonio)
>                    (state texas)
>                    (zip 75438))
>              (parents
>                  (father pete)
>                  (mother sue))
>              (children bob)
>              (name jane)
>              (weight 120)))
> ---------------------------
>
> I need to display the data under the key (e.g. (assockey parents jane)
would
> return ((father pete) (mother sue))
>
> Here is what I have as my function:
>
> (defun assockey (keyinput person)
>   (rest (assoc keyinput person)))
>
> but the error message I get is:
>
> Error in EVAL: Symbol has no value: PARENTS
>
> Control Stack Debugger
> Eval  #6: PARENTS
>
> They 'keyinput' variable is where I am having my problem.  Any hints on
how
> to get this?
>
> I'm a beginner with Lisp (as if you couldn't tell), so go easy on me :)
>
> Thanks,
>
> JD
>
>
From: Jeff Sandys
Subject: Re: Lisp Help
Date: 
Message-ID: <3D0E49F2.7E0AF393@juno.com>
I usually do this type of access 
with a property list and getf.  

LISP(6): (setf jill '(:address (:number 1201
			        :street main
			        :city san-antonio
			        :state texas
			        :zip 75438)
		      :parents (:father pete
		 	        :mother sue)
		      :children bob
		      :name jill
		      :weight 120))

LISP(7): (getf jill :parents)
(:FATHER PETE :MOTHER SUE)
LISP(8): (getf (getf jill :parents) :father)
PETE
LISP(9): (setf (getf jill :weight) 130) ;;; change jill's weight
130

Thanks,
Jeff Sandys


JD wrote:
> 
> I'm supposed to be writing a function that 
> receives a key and an association
> list of this form:
> 
> (setf jane '((jane address
>                    (number 1201)
>                    (street main)
>                    (city san-antonio)
>                    (state texas)
>                    (zip 75438))
>              (parents
>                  (father pete)
>                  (mother sue))
>              (children bob)
>              (name jane)
>              (weight 120)))
From: James A. Crippen
Subject: Re: Lisp Help
Date: 
Message-ID: <m3r8j5ge9w.fsf@kappa.unlambda.com>
Jeff Sandys <·······@juno.com> writes:

> LISP(6): (setf jill '(:address (:number 1201
> 			        :street main
> 			        :city san-antonio
> 			        :state texas
> 			        :zip 75438)
> 		      :parents (:father pete
> 		 	        :mother sue)
> 		      :children bob
> 		      :name jill
> 		      :weight 120))
> 
> LISP(7): (getf jill :parents)
> (:FATHER PETE :MOTHER SUE)
> LISP(8): (getf (getf jill :parents) :father)
> PETE
> LISP(9): (setf (getf jill :weight) 130) ;;; change jill's weight
> 130

The important thing to note here is that using keywords instead of
symbols means you don't have to worry about accidentally unquoted
symbols being evaluated.  Keywords always evaluate to themselves.

Some people favor the use of keywords for data delimiters like this.
Others claim that keywords should only be used for keyword arguments
to functions (and in similar cases).  On the third hand, some claim
that using keywords for data delimiters in this manner *is* consistent
with their use in lambda lists for function (etc) arguments.  This is
a stylistic issue that's up to the individual to decide, since the
language doesn't really care either way.

'james

-- 
James A. Crippen <·····@unlambda.com> ,-./-.  Anchorage, Alaska,
Lambda Unlimited: Recursion 'R' Us   |  |/  | USA, 61.20939N, -149.767W
Y = \f.(\x.f(xx)) (\x.f(xx))         |  |\  | Earth, Sol System,
Y(F) = F(Y(F))                        \_,-_/  Milky Way.
From: Joel Ray Holveck
Subject: Re: Lisp Help
Date: 
Message-ID: <y7c7kkx3p2i.fsf@sindri.juniper.net>
>> LISP(6): (setf jill '(:address (:number 1201
[snip]
> The important thing to note here is that using keywords instead of
> symbols means you don't have to worry about accidentally unquoted
> symbols being evaluated.  Keywords always evaluate to themselves.
> Some people favor the use of keywords for data delimiters like this.
[snip]
> Others claim that keywords should only be used for keyword arguments
[snip]

My preference is to not use keywords in such a scenario, simply so
that other libraries can store their data in the same structure too
without a namespace conflict.  Kinda like plists in some respects.

But I don't really feel strongly one way or another.  Certainly not
enough to criticize the guy who actually writes the code for his
choice.

Cheers,
joelh
From: Thomas F. Burdick
Subject: Re: Lisp Help
Date: 
Message-ID: <xcvd6uoqs3t.fsf@monsoon.OCF.Berkeley.EDU>
Joel Ray Holveck <·····@juniper.net> writes:

> >> LISP(6): (setf jill '(:address (:number 1201
> [snip]
> > The important thing to note here is that using keywords instead of
> > symbols means you don't have to worry about accidentally unquoted
> > symbols being evaluated.  Keywords always evaluate to themselves.
> > Some people favor the use of keywords for data delimiters like this.
> [snip]
> > Others claim that keywords should only be used for keyword arguments
> [snip]
> 
> My preference is to not use keywords in such a scenario, simply so
> that other libraries can store their data in the same structure too
> without a namespace conflict.  Kinda like plists in some respects.
> 
> But I don't really feel strongly one way or another.  Certainly not
> enough to criticize the guy who actually writes the code for his
> choice.

Well, I'd criticize someone who wrote code like that if I had to share
data structures with it -- otherwise, if it's safely in a single
module, it's okay I guess.  Of course, I'd probably use classes for
this instead, where you /have/ to use non-keyword symbols for slot
names (thankfully).

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Jock Cooper
Subject: Re: Lisp Help
Date: 
Message-ID: <m3660geeyi.fsf@jcooper02.sagepub.com>
Jeff Sandys <·······@juno.com> writes:

> I usually do this type of access 
> with a property list and getf.  
> 
> LISP(6): (setf jill '(:address (:number 1201
> 			        :street main
> 			        :city san-antonio
> 			        :state texas
> 			        :zip 75438)
> 		      :parents (:father pete
> 		 	        :mother sue)
> 		      :children bob
> 		      :name jill
> 		      :weight 120))
> 
> LISP(7): (getf jill :parents)
> (:FATHER PETE :MOTHER SUE)
> LISP(8): (getf (getf jill :parents) :father)
> PETE
> LISP(9): (setf (getf jill :weight) 130) ;;; change jill's weight
> 130
> 
> > I'm supposed to be writing a function that 
> > receives a key and an association
> > list of this form:
> > 
> > (setf jane '((jane address
> >                    (number 1201)
> >                    (street main)
> >                    (city san-antonio)
> >                    (state texas)
> >                    (zip 75438))
> >              (parents
> >                  (father pete)
> >                  (mother sue))
> >              (children bob)
> >              (name jane)
> >              (weight 120)))

Shouldn't there be a copy-list or something similar in here somewhere 
so that literals aren't being modified?
From: Joe Marshall
Subject: Re: Lisp Help
Date: 
Message-ID: <ekKP8.236681$352.18468@sccrnsc02>
"Jock Cooper" <·····@mail.com> wrote in message ···················@jcooper02.sagepub.com...
> Jeff Sandys <·······@juno.com> writes:
>
> > I usually do this type of access
> > with a property list and getf.
> >
> > LISP(6): (setf jill '(:address (:number 1201
> >         :street main
> >         :city san-antonio
> >         :state texas
> >         :zip 75438)
> >       :parents (:father pete
> >         :mother sue)
> >       :children bob
> >       :name jill
> >       :weight 120))
> >
> > LISP(7): (getf jill :parents)
> > (:FATHER PETE :MOTHER SUE)
> > LISP(8): (getf (getf jill :parents) :father)
> > PETE
> > LISP(9): (setf (getf jill :weight) 130) ;;; change jill's weight
> > 130
> >
>
> Shouldn't there be a copy-list or something similar in here somewhere
> so that literals aren't being modified?

YES!  (newbies take note)

(setf jill (list :address (list :number 1201
                                :street "Main Street"
                                :city   "San Antonio"
                                :state  "Texas"
                                :zip    75438)
                 :parents (list :father pete
                                :mother sue)
                 :name "Jill"
                 :weight 120))

(incf (getf jill :weight) 10)