unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Dynamic variable binding
@ 2008-11-12 19:53 Sebastian Tennant
  2008-11-12 22:05 ` Ludovic Courtès
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Sebastian Tennant @ 2008-11-12 19:53 UTC (permalink / raw)
  To: guile-user

Hi all,

An elementary scheme problem from an elementary schemer...

I need to create multiple variable bindings from a list of symbols.  The
value of the variables is unimportant.  It's the 'names' of the
variables that matter.

In pseudo-scheme code:

  (map (lambda (v) (define (eval v) "foo") '(var1 var2 var3)))

Clearly this won't work but I thought perhaps calling a macro in place
of the 'define' would do it, but...

 guile> (define-macro (definer var val)
          `(define ,var ,val))
 guile> (definer 'foo "bar")
 guile> foo
 ERROR: Unbound variable: foo
 ABORT: (unbound-variable)

No doubt this fails for the same reason this does:

 guile> (define 'foo "bar")
 guile> foo
 ERROR: Unbound variable: foo
 ABORT: (unbound-variable)

What exactly happens when you 'define' a symbol?

Any tips/pointers much appreciated.

Sebastian






^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Dynamic variable binding
@ 2008-11-12 22:37 dsmich
  0 siblings, 0 replies; 17+ messages in thread
From: dsmich @ 2008-11-12 22:37 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-user

---- "Ludovic Courtès" <ludo@gnu.org> wrote: 
> Sebastian Tennant <sebyte@smolny.plus.com> writes:
> > What exactly happens when you 'define' a symbol?
> 
> But, just like "`eval' is evil", run-time symbol definition doesn't
> sound right.  Surely, there are other ways that you could use to solve
> your problem more elegantly.

Sebastian,  instead of trying to use Guiles symbol and module namespaces as a hashtable, why not just use a hashtable directly?  ;^)

-Dale




^ permalink raw reply	[flat|nested] 17+ messages in thread
[parent not found: <200811130428.mAD4SQbi030880@cm-mail.stanford.edu>]

end of thread, other threads:[~2008-12-29 10:48 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-12 19:53 Dynamic variable binding Sebastian Tennant
2008-11-12 22:05 ` Ludovic Courtès
2008-11-13  0:51 ` Keith Wright
2008-12-19 11:50   ` Sebastian Tennant
2008-12-19 13:03     ` Ludovic Courtès
2008-12-19 15:46       ` Sebastian Tennant
2008-12-20  0:17     ` Keith Wright
2008-12-27 15:56       ` Sebastian Tennant
2008-12-28 22:56         ` Neil Jerram
2008-12-29 10:48           ` Sebastian Tennant
2008-11-13 11:33 ` Sebastian Tennant
2008-11-13 18:50   ` Ludovic Courtès
2008-11-14  6:14     ` Sebastian Tennant
2008-11-15 14:58       ` Jon Wilson
2008-11-15 16:59         ` Sebastian Tennant
  -- strict thread matches above, loose matches on Subject: below --
2008-11-12 22:37 dsmich
     [not found] <200811130428.mAD4SQbi030880@cm-mail.stanford.edu>
2008-11-13 14:10 ` Kjetil S. Matheussen

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).