unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-user@gnu.org
Subject: Re: Newbie question:  bind a variable on the fly
Date: Mon, 12 Jun 2006 23:17:48 +0100	[thread overview]
Message-ID: <87wtbmt3w3.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <448C55FA.4040708@fastmail.fm> (Jon Wilson's message of "Sun, 11 Jun 2006 12:42:18 -0500")

Jon Wilson <j85wilson@fastmail.fm> writes:

> (define-macro (dyn-set! var val)
>                `(begin (if (not (defined? (quote ,var)))
>                          (primitive-eval `(define ,(quote ,var) #f)))
>                        (set! ,var ,val)))
>
> (defined? 'undefined-symbol) ; => #f
> ;(set! undefined-symbol #t)  Gives an error.
> (dyn-set! undefined-symbol #t) ; No error.
> (defined? 'undefined-symbol) ; => #t

I think this mostly does what you want, but

- isn't ,(quote xxx) equivalent to just xxx?

- as you kind of said, it will go wrong if ,var is defined locally:
  defined? will be #f for a local variable, so a top-level variable
  with the same name will be created, but the set! will then set the
  local variable.

Regards,
    Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2006-06-12 22:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-10 10:25 Newbie question: bind a variable on the fly Vincent De Groote
2006-06-10 13:08 ` Marius Vollmer
2006-06-11 17:42 ` Jon Wilson
2006-06-12 22:17   ` Neil Jerram [this message]
2006-06-13 18:26     ` Jonathan Wilson
  -- strict thread matches above, loose matches on Subject: below --
2006-06-10 10:23 Vincent De Groote

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=87wtbmt3w3.fsf@ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    /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).