English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: Redefinition doesn't work
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-11-06 (22:11)
From: Stephan Houben <stephan@p...>
Subject: Re: Redefinition doesn't work
On Fri, 03 Nov 2000, Pierpaolo BERNARDI wrote:

> For example, in Common Lisp it is forbidden to redefine system functions.
> In Scheme, you can define functions with the same name of a system one,
> but this redefinition cannot change the behaviour of other system
> functions.

And this is not very nice, since this forbids the "obvious" way to 
implement various Scheme functions in terms of more primitive
ones. I.e. one would expect that Scheme implementations load
a preamble file which defines things like cadr as:

(define (cadr x) (car (cdr x)))

But this is incorrect, since redefining car would change the behavior of
cadr, which is explicitely forbidden. Correct way to do this:

(define cadr
    (let ((my-car car)
           (my-cdr cdr))
        (lambda (x) (my-car (my-cdr)))))

Of course, even more problematic is that user code needs to do similar
hacks if it wants to be stable against redefinitions of standard procedures.
Moreover, it complicates compiler optimisation an awful lot (it becomes
basically impossible at the toplevel; it can be done in a batch compiler
where the whole source can be inspected to rule out (set! car ...) things).

> > I just tried to
> > compile my Scheme files as usual, calling some primitive function
> > named compile-file (or so), that unfortunately happened to use a
> > global function also named compile.
> This is not a property of Scheme, is a bug in the implementation you
> were using!

Since compile-file is not a R5RS standard procedure, 
there is no guarantee that redefinition of *any* procedure might not change
the behavior of it.  This makes use of any 3d party library in your Scheme
program very problematic, unless the Scheme implementation provides
a (non-standard) module system that fixes this madness.

Of course, I probably don't have to tell all this to the O'Caml developers,
who wisely chose *not* to follow Scheme in this regard...

ir. Stephan H.M.J. Houben
tel. +31-40-2474358 / +31-40-2743497
e-mail: stephanh@win.tue.nl