[plt-scheme] Re: cannot require 19.ss (srfi)

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jan 6 16:26:55 EST 2005

On Jan  6, Hans Oesterholt-Dijkema wrote:
> I see your argument, and can imagine this to some degree.  However,
> there are other ways to tackle this.  E.g. bigloo only complains
> about overriding a primitive or function, but doesn't stop
> working. [...]

That seems rather arbitrary.  One thing is that "primitives" is a very
shaky concept, another is that I don't see why "overriding" a function
is worse than overriding other values.  Third, what is exactly
"overriding"? -- is it changing the binding which affects all code?
The current module?  Toplevel user code?

> 3. If I'm correct it is also possible to redefine the
>    original primitives using some special construct.

No, you cannot touch them.  You can define new ones and provide a
language module that will use your new things under the same name, but
the original bindings are still there, and still untouched.  This is an
*extremely* nice property especially if you want to "redefine" stuff.

For example -- say I wrote some module that does something with pairs:

  (module eli mzscheme
    (provide make-interval)
    (define (make-interval from to) (cons from to))

and say you're teaching a class, and like many people, you believe
that `cons' should be used to construct lists only.  So you build a
language module to redefine `cons':

  (module hans mzscheme
    (provide (all-from-except mzscheme cons)
             (rename my-cons cons))
    (define (my-cons x y)
      (if (list? y)
        (cons x y)
        (error 'cons "bad code"))))

Now it is possible to write code in your new language, which can still
use my code:

  (module foo hans
    (require eli)
    (provide a b)
    (define (a) (make-interval 1 2))
    (define (b) (cons 1 2)))

So you get:

  > (require foo)
  > (a)
  (1 . 2)
  > (b)
  cons: bad code

The top-level makes things confusing since requiring stuff really
"copies" bindings over.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.