This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: Assignment to syntactic keywords in guile
- To: Keith Wright <kwright at tiac dot net>
- Subject: Re: Assignment to syntactic keywords in guile
- From: Jim Blandy <jimb at red-bean dot com>
- Date: 06 Oct 1999 17:01:13 -0500
- Cc: jl_daschbach at pnl dot gov, guile at sourceware dot cygnus dot com
- References: <199910060432.AAA00657@kwright.tiac.net>
I actually think R5RS articulates a pretty clear model for how this
works:
Every valid usage of an identifier has lexically apparent binding. It
might be either a syntactic binding or a variable binding.
Identifiers can be used as either keywords or variables. In some
contexts, it is clear from the grammar which is meant. For example,
`x' in `(+ x 3)' must be a variable reference. In other contexts, you
need to know identifier's binding to decide what form of expression
you have: in `(x 3)', you need to know the binding of `x' to tell
whether this is a <procedure call> or something else.
Under this model, an expression like (set! x set!) is incorrect
because the last use of `set!' takes place in a context which requires
it to be a variable reference, but set! has no binding in scope. A
Scheme system should treat this as a reference to an unbound variable.
Guile happens to allow it, due to quirks of its implementation.
Under this model, an expression like (let ((set! +)) (set! x 4)) is
valid, and returns x + 4. The let introduces a new binding for set!,
and in the subexpression `(set! x 4)', the fact that set! is bound to
a variable means we have a <procedure call>, not an <assignment>.
Argh. I don't have time to write this all out clearly. But I think
if you read through R5RS, you'll find it's pretty clear about how this
is all supposed to work. But like so many things in R5RS, you have to
pull together little comments scattered throughout the document to see
the big picture. It's a damned good thing it's only fifty pages long.