[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] top level environment hygiene in Chicken source

From: Thomas Bushnell BSG
Subject: [Chicken-hackers] top level environment hygiene in Chicken source
Date: Mon, 28 Dec 2009 17:04:46 -0800

I'm confused about how the Chicken source maintains proper top level
environment hygiene.  

R5RS has the rule that if you redefine a top-level standard procedure,
other top-level procedures must continue to have their standard

So, in library.scm, we find for example that the string procedure is
defined thus:

(define string
  (let ([list->string list->string])
    (lambda chars (list->string chars)) ) )

That way, if list->string gets assigned, the behavior of string doesn't
change because it uses the lexically captured value rather than the
current binding at call time.

But then, why does cdddr work?  Here is it's definition:

(define (cdddr x) (cdr (cdr (cdr x))))

I have verified that cdddr continues to work even if cdr is reassigned,
as it should.  But I can't figure out for the life of me how the source
guarantees that result.  (Of course, the "usual-integrations"
declaration *permits* the compiler to get that result, but it doesn't
require it.)

And, if whatever works for cdddr works, why doesn't it work for string?

Most of the procedures in library.scm are defined without the protecting
let capture; and by contrast, most procedures elsewhere are not.  Look,
for example, that repl in eval.scm captures seven top level names this
way.  But not everything: it uses eof-object?, for example, without
capturing it.  And eval.scm doesn't even have usual-integrations (or
equivalent) declarations!

I can see in eval.scm that there is careful and explicit environment
handling, which of course makes sure that extra bindings don't show up.
But what ensures that top level set! isn't interfering with library
procedures?  How is it that null-environment needs to save the value of
make-vector, but not pair? or car or fx< or ...?

A related question: in compiled code, what is the equivalent to the
setup for the environments in eval.scm?  

reply via email to

[Prev in Thread] Current Thread [Next in Thread]