This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Assignment to syntactic keywords in guile



       In a recent discussion on the Kawa list I have learned that my
understanding of scheme was in error with regards to the recent Rxrs
docuements.  This disussion was prompted by Per pointing out to
someone that (define old-set! set!) was not legal scheme since set!
was a syntactic keyword and does not satisfy the syntax of an
expression, which the operand of a 'define' must be.  Guile allows
such constructs.  Per has said that syntactic keywords must be
disjoint from variables, but at this point I disagree.  I have however
lost every discussion refering to the Rxrs standards, and Per is
certainly more knowledgable about scheme than I.  I thought that
perhaps this issue might be important to the guile folks, who have
chosen to be non-compliant on this point.  

	It turns out that scm through 5c4, but not the more recent
versions, and guile, at least 1.3.5, allow both the construct above,
and the rebinding of a syntactic keyword using the variable binding
forms.  All of this is not allowed by r4rs and r5rs, although r4rs is
a bit unclear on this, stating that:

  Some implementations allow all identifiers, including syntactic
  keywords, to be used as variables.  This is a compatible extension to
  the language, but ambiguities in the language result when the
  restriction is relaxed, and the ways in which these ambiguities are
  resolved vary between implementations.

        So it is ilegal to write (define old-set! set!) and
(old-set! set! #f).

        It appears from this that any language that allows syntactic
keywords to be used as variables is a "compatible extension" of r4rs
scheme, but not a compliant implementation.  R5RS has removed this
statement.

	I now understand that although a great deal is made of
procedures being first class objects in scheme, a syntax is a
different semantic construct.  An identifier representing a syntax is
a syntactic keyword and one representing a location is a variable.
Although a procedure application may look identical to the application
of a syntax the identifiers which bind to these forms must be treated
with non-intersecting sets of binding/rebinding forms.
     
	To me, this partitioning seems at odds with the goal of
elegance and flexibility that the authors of scheme mention.  In this
mode however they declare that new syntactic keywords may be created
by the define-syntax constructs.  Thus any identifier which behaves
like a procedure may in fact be a syntax and thus it is now an error
to use the define/set!/let forms with it as the operand.

       I expect Rxrs won't change, so I wonder what the guile team
will do.  Presently guile accepts the following, which works as I have
always expected, but which is in error according to r4/5rs:

guile> (define old-set! set!)
guile> (define a 1)
guile> (old-set! a 2)
guile> a
2
guile> (set! set! (lambda (a b) (list a b)))
guile> (set! a 5)
(2 5)
guile> a
2
guile> (old-set! a 10)
guile> a
10
guile> (old-set! set! old-set!)
guile> (set! a 20)
guile> a
20

	The above toy example to me represents the behavior I expected
in scheme, but which is in fact not r4/5rs legal scheme.  Since most
lambda procedures may be rewritten as a syntax, completely portable
code that uses identifiers which represent syntax's or lambda's as
expressions (e.g. the operand of a set!) must wrap these forms in a
conditional syntax, rather than as above.  


	



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]