From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA13060 for caml-red; Mon, 6 Nov 2000 23:11:37 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA01496 for ; Mon, 6 Nov 2000 10:38:33 +0100 (MET) Received: from pcrm.win.tue.nl (pcrm.win.tue.nl [131.155.69.41]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eA69cX127898; Mon, 6 Nov 2000 10:38:33 +0100 (MET) Received: from pcrm (stephan@localhost [127.0.0.1]) by pcrm.win.tue.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) with SMTP id KAA30883; Mon, 6 Nov 2000 10:42:01 +0100 From: Stephan Houben Reply-To: stephanh@win.tue.nl Organization: Scientific Computing Group To: Pierpaolo BERNARDI , Pierre Weis Subject: Re: Redefinition doesn't work Date: Mon, 6 Nov 2000 10:29:22 +0100 X-Mailer: KMail [version 1.0.28] Content-Type: text/plain Cc: caml-list@inria.fr References: In-Reply-To: MIME-Version: 1.0 Message-Id: <00110610420100.30858@pcrm> Content-Transfer-Encoding: 8bit Sender: weis@pauillac.inria.fr 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... Stephan -- ir. Stephan H.M.J. Houben tel. +31-40-2474358 / +31-40-2743497 e-mail: stephanh@win.tue.nl