From: Ray Dillinger <[email protected]>
Subject: Re: [r6rs-discuss] Proposed features for small Scheme, part 1: a stake 
in the ground
Date: Fri, 11 Sep 2009 11:47:03 -0700

> To wit: Redefinitions of primitive procedures (such as car and 
> cdr) or primitive syntax (such as lambda) do not alter the 
> semantics of other primitive procedures (such as length), even
> if the latter is defined in terms of the former.
> 
> Also: (also R4RS, R5RS, R6RS) using set! to change a binding is 
> only allowed if it is in the scope of a define that establishes 
> that binding.  IOW, you can only mutate a definition created by
> your own code.  So, if you shadow the variable whose name is 'cdr', 
> by placing a 'define' in your own scope, you can mutate it all 
> you want but that doesn't affect the binding in the larger 
> "zeroth" scope in which the primitive (that other procedures 
> depend on) is defined. 

I like this way, and actually Gauche works pretty close to this.
Though I don't think R6RS restriction is a showstopper, since
I can always use 'except' or 'rename' the imported name, which is
annoyance at most.

If we relax the restriction and allow shadowing define, we need
to clearify resolution of forward reference.   For example:

  (import (foo-library))   ; imports name "foo", possibly a syntax.
  (define x (foo 42))
  (define (foo n) (* n n))

Which "foo" should be used to compute x, the imported one or
the one defined in the current module?
Or should this be an error? (which isn't bad, imho)


I think the extreme end of dynamism, in which redefinition
can alter the behavior of all procedures that depend on 
the redefined binding, isn't desirable for most of the cases.
You can't know the scope of the effect of the redefition,
and it is not guaranteed that the effect of the redefinition
is the same after third-party library is updated.
You definitely need to control the scope of the effect.

Sometimes it is handy to redefine something in existing
modules, e.g. for debugging or to workaround a bug (in CL
development, messing around unexported symbols in a
third-party library has saved my day more than once.)

I personally think it's ok to make such feature
implementation-dependent extension.  But if we need to
agree on the protocol, what we need is a form that explicitly
specifies which module's binding is altered/shadowed.

--shiro



_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to