[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dynamic variable binding
From: |
Keith Wright |
Subject: |
Re: Dynamic variable binding |
Date: |
Wed, 12 Nov 2008 19:51:27 -0500 |
> From: Sebastian Tennant <address@hidden>
>
> 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?
I don't know what happens (in Guile), but I can tell
you what _should_ happen. (In my humble opinion as
a demi-god of semantics.)
Scheme> (define 'foo "bar")
at a very early stage (like in the reader) this is
Scheme> (define (quote foo) "bar")
There are several possiblities
(1) error message in define
(1a) Rude: Thou fool! |quote| is not a variable
(1b) Polite: If you are sure you want to do that,
write out the quote, don't use apostrophe
(1c) Obscure: Bad variable in def_schkdt
(2) Redefine quote
(2a) In a new local scope: 'a is a call to procedure
|quote| with argument the value of |a|, argument is
evaluated, ignored, and 'a -> "bar" if |a| is defined.
(2b) Hell breaks loose: All uses of |quote| in previously
defined system procedures now have a new meaning.
e.g. depending on exact code for |abs|, maybe
(abs -3) -> "bar"
But you are asking the wrong question. Ask not
what happens when a symbol is defined, ask what
you can do to make the macro define an unquoted
variable.
-- Keith
PS: Experiments with an old version of Guile indicate (2).
To distinguish (2a) from (2b) would require work or knowledge.
guile> (version)
"1.6.4"
guile> (define 'foo "bar")
guile> (quote 3)
"bar"
guile> '3
"bar"
guile> 'foo
standard input:6:4096: While evaluating arguments to quote in expression (quote
foo):
standard input:6:4096: Unbound variable: foo
ABORT: (unbound-variable)