guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamic variable binding


From: Kjetil S. Matheussen
Subject: Re: Dynamic variable binding
Date: Thu, 13 Nov 2008 15:10:21 +0100 (CET)


Sebastian Tennant:

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


That's a common problem.
Maybe this is one good enough:

(define-macro (define-lotsof names value)
   `(begin
      ,@(map (lambda (name)
                `(define ,name ,value))
             names)))

(define-lotsof (a b c) "foo")

If not, you may need to play with local-eval or similar.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]