From: Tayssir John Gabbour
Subject: Re: Problem help involving association lists and keys
Date: 
Message-ID: <1119285355.375178.23170@f14g2000cwb.googlegroups.com>
AusTex wrote:
> I was hoping to get some assistance on a few exercises I am currently
> working on involving association lists and keys/values.
>
> I am dealing with an association list of 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 define a function that receives a key, a value, and an
> association list of the form above and returns a modified association
> list where (key value) is inserted into the original association list.
> Should I be using the subst function or maybe cons?

One minor thing, with a simple solution. If you're intending to
destructively modify this QUOTE'd structure with things like setf, as
opposed to returning a fresh modified copy with your function, one Lisp
gotcha is that doing so is undefined by the spec.
http://lisp.tech.coop/Lisp%20Gotchas

(I suppose the reason is that Lisp has had to be compatible with things
that store pieces of programs in ROM, or you wouldn't want some macro
to really go nuts changing code.)

Solution: use COPY-TREE.

(setf jane (copy-tree
              '((jane (address
                ...)))))


Tayssir