* define and modules
@ 2002-10-20 16:17 Dirk Herrmann
2002-11-03 16:25 ` Marius Vollmer
0 siblings, 1 reply; 10+ messages in thread
From: Dirk Herrmann @ 2002-10-20 16:17 UTC (permalink / raw)
On 19 Oct 2002, Marius Vollmer wrote:
> Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
>
> > Summarized:
> > * The compiler must be able to emit code that allows references to
> > identifiers to be looked up at use time (that is, in the executor).
> > * The executor must be able to handle definitions.
> > * Once a binding has been referenced, the binding should not change.
>
> Yes, that's exactly the way I see it as well. The constraints that
> new-model.txt puts on the module system work in this direction.
Great. However, currently, guile's handling of defines is buggy or at
least in contrast to R5RS. Changing it would break existing code as shown
in the following two examples:
Example 1:
==========
(define x (begin (set! x #f) #t))
--> ERROR: Unbound variable: x
If I understand R5RS correctly, (define x y) should first bind the
identifier x to a location and _then_ execute the assignment (set! x y).
That means, guile's behaviour is wrong here. The reason is, that guile
first executes y and _afterwards_ binds and assigns x. This bug could be
fixed by changing the order in which guile deals with defines. However,
then we would have a problem with the following code:
Example 2:
==========
(define-module (guile))
(define foo #t)
(define-module (bar))
foo
--> #t
(define foo (not foo))
foo
--> #f
(define-module (guile))
foo
--> #t
According to R5RS, a 'define expression on the top-level has exactly the
same effect as an assignment expression if the identifier is bound.
Guile, however, behaves differently here: An expression (define x y)
executes y making use of bindings that potentially come from other
modules. Then, if x is bound _within_the_current_module_ an assignment is
performed. Otherwise, if x is not bound or bound in another module, a new
binding is created in the current module.
Example 1 and 2 show two aspects where the current handling of guile's
define is wrong (with respect to R5RS): First, if a binding exists, guile
does not simply perform an assignment, and second, if no binding exists,
guile does not as a first step create one.
Unfortunately, there is code that depends on this behaviour:
(define-module (srfi srfi-17) ...)
...
(define setter
(getter-with-setter
setter
(lambda args
(error "Setting setters is not supported for a good reason."))))
In fact, the way guile currently handles 'define expressions, bindings get
re-defined after they have been referenced! Look at the following
expression:
(define-module (guile))
(define foo #t)
(define-module (bar))
(define (old) foo) ; references the old binding in module (guile)
(old)
--> #t
(define foo #f) ; new binding for foo in module (bar)
(define (new) foo) ; references the new binding in module (bar)
;; and now:
;; new and old reference different bindings for foo:
(new)
--> #f
(old)
--> #t
Best regards,
Dirk Herrmann
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-10-20 16:17 define and modules Dirk Herrmann
@ 2002-11-03 16:25 ` Marius Vollmer
2002-11-04 21:32 ` Dirk Herrmann
0 siblings, 1 reply; 10+ messages in thread
From: Marius Vollmer @ 2002-11-03 16:25 UTC (permalink / raw)
Cc: guile-devel
Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
> Great. However, currently, guile's handling of defines is buggy or at
> least in contrast to R5RS. Changing it would break existing code as shown
> in the following two examples:
I see. I'd say we don't need to slavishly follow R5RS here since R5RS
does not talk about modules. And we don't need to keep our current,
mostly accidental semantics either. So there is opportunity to do the
Right Thing...
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-11-03 16:25 ` Marius Vollmer
@ 2002-11-04 21:32 ` Dirk Herrmann
2002-11-04 22:12 ` Marius Vollmer
0 siblings, 1 reply; 10+ messages in thread
From: Dirk Herrmann @ 2002-11-04 21:32 UTC (permalink / raw)
Cc: guile-devel
On 3 Nov 2002, Marius Vollmer wrote:
> Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
>
> > Great. However, currently, guile's handling of defines is buggy or at
> > least in contrast to R5RS. Changing it would break existing code as shown
> > in the following two examples:
>
> I see. I'd say we don't need to slavishly follow R5RS here since R5RS
> does not talk about modules. And we don't need to keep our current,
> mostly accidental semantics either. So there is opportunity to do the
> Right Thing...
OK, talking about the right thing: How should guile react to the
following code:
(define define-private define)
This is done in boot9.scm. Should this be allowed?
Best regards,
Dirk Herrmann
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-11-04 21:32 ` Dirk Herrmann
@ 2002-11-04 22:12 ` Marius Vollmer
2002-11-06 6:54 ` Dirk Herrmann
0 siblings, 1 reply; 10+ messages in thread
From: Marius Vollmer @ 2002-11-04 22:12 UTC (permalink / raw)
Cc: guile-devel
Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
> OK, talking about the right thing: How should guile react to the
> following code:
>
> (define define-private define)
>
> This is done in boot9.scm. Should this be allowed?
No, since 'define' is a syntactic keyword... which is probably not the
reason you were expecting, right?
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-11-04 22:12 ` Marius Vollmer
@ 2002-11-06 6:54 ` Dirk Herrmann
2002-11-06 7:16 ` Lynn Winebarger
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Dirk Herrmann @ 2002-11-06 6:54 UTC (permalink / raw)
Cc: guile-devel
On 4 Nov 2002, Marius Vollmer wrote:
> Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
>
> > OK, talking about the right thing: How should guile react to the
> > following code:
> >
> > (define define-private define)
> >
> > This is done in boot9.scm. Should this be allowed?
>
> No, since 'define' is a syntactic keyword... which is probably not the
> reason you were expecting, right?
It is exactly the reason. The question is, how should guile react here?
Or, what should a memoizer do with this code? I currently just leave the
symbol define where it is, that is my memoizer makes
(#@define define-private define)
from that expression. This results then in a 'unbound symbol' error,
since the executor does not care for macros any more. This solution makes
sense if the example is slightly different:
(begin
(define and #t)
(define foo and))
Here, the memoizer would first memoize the code to:
(#@begin
(#@define and #t)
(#@define foo and))
and the executor would find a valid non-macro definition for 'and' when it
tries to execute the definition for 'foo'.
So, what do you think should be guile's behaviour?
Best regards
Dirk
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-11-06 6:54 ` Dirk Herrmann
@ 2002-11-06 7:16 ` Lynn Winebarger
2002-11-06 17:20 ` Dirk Herrmann
2002-11-06 22:27 ` Dirk Herrmann
2002-11-17 20:30 ` Marius Vollmer
2 siblings, 1 reply; 10+ messages in thread
From: Lynn Winebarger @ 2002-11-06 7:16 UTC (permalink / raw)
Cc: guile-devel
On Wednesday 06 November 2002 01:54, Dirk Herrmann wrote:
> On 4 Nov 2002, Marius Vollmer wrote:
>
> > Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
> >
> > > OK, talking about the right thing: How should guile react to the
> > > following code:
> > >
> > > (define define-private define)
> > >
> > > This is done in boot9.scm. Should this be allowed?
> >
> > No, since 'define' is a syntactic keyword... which is probably not the
> > reason you were expecting, right?
>
> It is exactly the reason. The question is, how should guile react here?
"Syntax error: invalid use of define" or "Syntax error: invalid define form"?
Lynn
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-11-06 7:16 ` Lynn Winebarger
@ 2002-11-06 17:20 ` Dirk Herrmann
2002-11-06 17:51 ` Lynn Winebarger
0 siblings, 1 reply; 10+ messages in thread
From: Dirk Herrmann @ 2002-11-06 17:20 UTC (permalink / raw)
Cc: guile-devel
On Wed, 6 Nov 2002, Lynn Winebarger wrote:
> On Wednesday 06 November 2002 01:54, Dirk Herrmann wrote:
> > On 4 Nov 2002, Marius Vollmer wrote:
> >
> > > Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
> > >
> > > > OK, talking about the right thing: How should guile react to the
> > > > following code:
> > > >
> > > > (define define-private define)
> > > >
> > > > This is done in boot9.scm. Should this be allowed?
> > >
> > > No, since 'define' is a syntactic keyword... which is probably not the
> > > reason you were expecting, right?
> >
> > It is exactly the reason. The question is, how should guile react here?
>
> "Syntax error: invalid use of define" or "Syntax error: invalid define form"?
I think this is not general enough. It works for the special case of
define, but the point is not, that the define form is broken, but that a
macro is used as an argument to something else. Consider
(call-foo define)
The point that we have to decide is, whether such a form is reported as a
syntax error during memoization, or whether we just don't dereference the
macro during memoization and let the executor do the lookup. The second
choice will allow that a new definition of the macro may be provided in
the meantime. For example:
(define (foo) (call-foo and))
(define and #t)
(foo)
Should this be possible? If so, then can't signal an error
_during_memoization_ if a macro is used at some illegal place.
Best regards,
Dirk
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-11-06 17:20 ` Dirk Herrmann
@ 2002-11-06 17:51 ` Lynn Winebarger
0 siblings, 0 replies; 10+ messages in thread
From: Lynn Winebarger @ 2002-11-06 17:51 UTC (permalink / raw)
Cc: guile-devel
On Wednesday 06 November 2002 12:20, Dirk Herrmann wrote:
> On Wed, 6 Nov 2002, Lynn Winebarger wrote:
> > > > > (define define-private define)
> > "Syntax error: invalid use of define" or "Syntax error: invalid define form"?
>
> I think this is not general enough. It works for the special case of
> define, but the point is not, that the define form is broken, but that a
> macro is used as an argument to something else.
You mistake which 'define the error refers to I think. It refers to
the 2nd appearance of 'define, not the first; `form' refers to
the bare identifier. Because macro expansion should occur _before_
the evaluation of the arguments of the outer define.
In other words: You're right that it shouldn't be detected as
special case of the outer define failing, but rather as one of the
macro expansion failing.
Lynn
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-11-06 6:54 ` Dirk Herrmann
2002-11-06 7:16 ` Lynn Winebarger
@ 2002-11-06 22:27 ` Dirk Herrmann
2002-11-17 20:30 ` Marius Vollmer
2 siblings, 0 replies; 10+ messages in thread
From: Dirk Herrmann @ 2002-11-06 22:27 UTC (permalink / raw)
Cc: guile-devel
On Wed, 6 Nov 2002, Dirk Herrmann wrote:
> On 4 Nov 2002, Marius Vollmer wrote:
>
> > Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
> >
> > > OK, talking about the right thing: How should guile react to the
> > > following code:
> > >
> > > (define define-private define)
> > >
> > > This is done in boot9.scm. Should this be allowed?
> >
> > No, since 'define' is a syntactic keyword... which is probably not the
> > reason you were expecting, right?
>
> It is exactly the reason. The question is, how should guile react here?
And, another question, how should the code in boot9.scm be changed? I
don't know why the definition was done at all, but I am not really sure if
there is some module-system trick behind it.
Best regards,
Dirk
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: define and modules
2002-11-06 6:54 ` Dirk Herrmann
2002-11-06 7:16 ` Lynn Winebarger
2002-11-06 22:27 ` Dirk Herrmann
@ 2002-11-17 20:30 ` Marius Vollmer
2 siblings, 0 replies; 10+ messages in thread
From: Marius Vollmer @ 2002-11-17 20:30 UTC (permalink / raw)
Cc: guile-devel
Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
> On 4 Nov 2002, Marius Vollmer wrote:
>
> > Dirk Herrmann <dirk@sallust.ida.ing.tu-bs.de> writes:
> >
> > > (define define-private define)
> > >
> > > This is done in boot9.scm. Should this be allowed?
> >
> > No, since 'define' is a syntactic keyword... which is probably not the
> > reason you were expecting, right?
>
> It is exactly the reason. The question is, how should guile react here?
It should not allow this (just like you implemented it).
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2002-11-17 20:30 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-20 16:17 define and modules Dirk Herrmann
2002-11-03 16:25 ` Marius Vollmer
2002-11-04 21:32 ` Dirk Herrmann
2002-11-04 22:12 ` Marius Vollmer
2002-11-06 6:54 ` Dirk Herrmann
2002-11-06 7:16 ` Lynn Winebarger
2002-11-06 17:20 ` Dirk Herrmann
2002-11-06 17:51 ` Lynn Winebarger
2002-11-06 22:27 ` Dirk Herrmann
2002-11-17 20:30 ` Marius Vollmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).