[plt-scheme] Preventing built-in functions to be redefined

From: Jos Koot (jos.koot at telefonica.net)
Date: Thu Jun 4 16:04:00 EDT 2009

Define is not a function (nor a procedure). define (redefining it as a variable) , define-syntax , define-for-syntax  and similar 
forms are treated specially, because they may alter the meaning of what is yet to come within a module.

However, you can freely write
#lang scheme
(define add1 sub1)
(add1 3) --> 2

To great extent this possibility also exist for the redifinition of syntaxes, but the redefinition of define and define-syntax and 
related forms are exceptions. They are also mentioned as exceptions in RnRS. Allowing them would create inconsistencies when 
compiling/interpretering programs containing such forms..

One of the consequences is that a syntax-case-form cannot refer to compile time procedures that have not yet been 
defined-for-syntax.
It is puzzling, I agree, but after some thinking it makes sense after all.

In earlier versions of PLT scheme #lang scheme did not allow any redifinition of syntax or variable. I asked to change that and I am 
glad my question was honoured. And I am also glad that the restriction to redefining define and define-syntax was excepted. BTW you 
can redefine all syntaxes, all define and define-syntax forms includes, by putting their definitions in a separate module (defining 
them under a different name and exporting them by any name tou want)
Jos

----- Original Message ----- 
From: "Noel Welsh" <noelwelsh at gmail.com>
To: "chaguidiao" <chaguidiao at gmail.com>
Cc: <plt-scheme at list.cs.brown.edu>
Sent: Thursday, June 04, 2009 5:48 PM
Subject: Re: [plt-scheme] Preventing built-in functions to be redefined


I don't remember if there is a parameter to change this behaviour. One
way to get the effect you want is to require the language your module
is written. Try this and you'll get an error about redefinition

#lang scheme

(require scheme)
(define define 5)

In the years I've been writing Scheme this has never caused a problem for me.

N.

On Thu, Jun 4, 2009 at 3:24 PM, chaguidiao <chaguidiao at gmail.com> wrote:
> Hi
>
> I am fairly new in Scheme. May I know if it is possible to restrict
> the redefinition of the built-in function, or if possible, make any
> other user-defined functions non-writable? Pardon me for being a
> little paranoid, but the fact that (define define 5) actually making
> "define" equals to 5 is just somewhat alarming to me.
>
> Thanks.
> nandehutu
_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.