[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
macros expanding into definitions
Date: Wed, 2 Dec 92 14:35:11 -0800
From: William Clinger <will@skinner.cs.uoregon.edu>
Aubrey Jaffer writes:
....I would
still prefer that (if a variable is DEFINEd) a DEFINE of a variable be
required to precede SET!s of that variable....
I also think that allowing a SET! to precede a DEFINE that binds the
variable it assigns will be confusing, but I think Jaffer's suggestion
would be confusing also. Does Jaffer mean to suggest that the DEFINE
must precede the SET! statically or dynamically? Both are confusing:
(define (foo)
; "statically precedes"
(cond ((read) (define x) (foo))
((read) => (lambda (y) (set! x y) (foo)))
(else x)))
(define (foo)
; "dynamically precedes"
(cond ((read) => (lambda (y) (set! x y) (foo)))
((read) (define x) (foo))
(else x)))
Both of these code examples are illegal to my understanding. I would
be against allowing DEFINEs in any Scheme construct. In the current
restriction, DEFINEs can only appear in a <body>, BEGIN, or top level.
In those constructs, there is no difference between the lexical and
dynamic order.
So I think any generalization of internal definitions is going to
make people more confused, not less confused, regardless of whether
we:
* allow internal DEFINE anywhere, with no restriction; or
* require internal DEFINE to precede references and assignments
statically; or
* require internal DEFINE to precede references and assignments
dynamically.
Please note that I have assumed that any restrictions placed on the
relationship between DEFINE and SET! would apply equally to references.
Instead of the current restriction of internal defines to the
beginning of a <body>, how about this: Internal defines are restricted
to appearing in a <body> or a <begin> in a <body> or a <begin> in a
<begin> in a <body>... Any SET!s or references to an internally
defined variable must occur after an internal definition of that
variable. DEFINEs for a variable after the initial DEFINE in a <body>
(or top level) are equivalent to SET!s.
This spec avoids the problem of your example and satisfies GJR's
property that a working top level program can be encapsulated by LET.