Mark Polesky <markpole...@yahoo.com> writes:

> (define my-alist
>   '((a . 1)
>     ))
>     
> (set! my-alist (acons 'b 2 my-alist))
>
> my-alist ==> ((b . 2) (a . 1))
>
> (define (alist-prepend alist key value)
>   (set! alist (acons key value alist)))
>
> (alist-prepend my-alist 'c 3)
>
> my-alist ==> ((b . 2) (a . 1))

There is no real copy involved; `my-alist' points to a non-immediate
value and so the only reason your `set!' does not work is because it is
reassigning the binding `alist' within `alist-prepend'.

This smells a bit like homework, however, and so how to achieve the
result you desire is left as an exercise (a very simple one at that--if
it's still not obvious and this isn't homework naturally an answer will
be provided, but just in case...). Ask yourself: *why* do you want to
destructively modify the original list? Do you even have to modify the
value of `my-alist' to achieve what you wish?

-- 
unknownlamer: online dating is dumb in general 
emacsen: computer dating rocks. I love computer
emacsen: I mean I really LOVE computers ;)


Reply via email to