[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: where define is legal



   Offhand, the following definition seems bogus:

   (define (foo bool)
     (if bool
	 (define (result) #true)
	 (define (result) #false))
     (result))

   And indeed, when I try to run this in MacScheme, I get an error message.

   I agree with the semantics, but I couldn't find anything in the R3
   description of DEFINE which restricts where it may appear.

   Some people from non-scheme backgrounds might think programmatic DEFINEs
   perfectly reasonable, so it's probably worth mentioning the restriction
   in the language description. 

In R4 and the Standard draft, section 5.2 on definitions begins:

   Definitions are valid in some, but not all, contexts where expressions
   are allowed.  They are valid only at the top level of a <program>
   and at the beginning of a <body>.

This makes the above example syntactically bogus.