unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Clinton Ebadi <clinton@unknownlamer.org>
To: Mark Polesky <markpolesky@yahoo.com>
Cc: guile-user@gnu.org
Subject: Re: passing an alist to a procedure without making a copy?
Date: Sun, 19 Apr 2009 13:35:29 -0400	[thread overview]
Message-ID: <877i1gk0m6.fsf@unknownlamer.org> (raw)
In-Reply-To: <484811.24959.qm@web83405.mail.sp1.yahoo.com> (Mark Polesky's message of "Sat, 18 Apr 2009 15:57:28 -0700 (PDT)")

Mark Polesky <markpolesky@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 ;)




  parent reply	other threads:[~2009-04-19 17:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-18 22:57 passing an alist to a procedure without making a copy? Mark Polesky
2009-04-19  1:20 ` Linas Vepstas
2009-04-19  7:30   ` r6rsguy
2009-04-19 17:35 ` Clinton Ebadi [this message]
2009-04-20 23:36   ` Neil Jerram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877i1gk0m6.fsf@unknownlamer.org \
    --to=clinton@unknownlamer.org \
    --cc=guile-user@gnu.org \
    --cc=markpolesky@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).