I am using:
DrScheme, version 208.
Language: Textual (MzScheme, includes R5RS).
I have entered the following definition:
(define arctic
(make-environment
(define animal 'polarbaer)))
(define ocean
(make-environment
(define animal 'shark)))
And obtain the following error:
Welcome to DrScheme, version 208.
Language: Textual (MzScheme, includes R5RS).
define: not allowed in an expression context in: (define animal (quote
polarbaer))
>
What is wrong?
My lecture notes state the above definition as an example but I cannot get
it working :-(
Any help is appreciated.
Thanks.
Some scheme implementations can have "define" implemented with other
semantics but in MzScheme, and as stated in the R5RS, definitions are valid
at top level and at the beginning of a body. This means that "define"
normally could only be used with forms like let other defines, etc that
expect a body.
> What is wrong?
> My lecture notes state the above definition as an example but I cannot get
> it working :-(
In MzScheme there is no "make-environment" also. I don't know what your
letcures are about but you could use other operators. An example that
probably does not do what you want is:
(define artic (let ((environment (null-environment 5)))
(eval '(define animal 'polarbaer)
environment)
environment))
"artic" will be and environment that, besides simple syntactic definitions,
has animal defined as the symbol "polarbaer".
Does anyone know a Scheme implemenentation where my samplecode might run?
So, one which knows make-environment and can have define implemented with
other semantics?
Thanks.
>>>And obtain the following error:
>>>
>>>Welcome to DrScheme, version 208.
>>>Language: Textual (MzScheme, includes R5RS).
>>>define: not allowed in an expression context in: (define animal (quote
>>>polarbaer))
Your lecture notes probably define environments before giving the
above examples.
Are the lecture notes online somewhere?
--
Jens Axel Søgaard
> Does anyone know a Scheme implemenentation where my samplecode might run?
> So, one which knows make-environment and can have define implemented with
> other semantics?
Both MIT Scheme and UMB Scheme have the "make-environment". If you want you
can define it in MzScheme with more or less the same semantic:
(define-syntax make-environment
(syntax-rules ()
((_ definition ...)
(let ((environment (scheme-report-environment 5)))
(eval '(begin definition
...)
environment)
environment))))
(define arctic
(make-environment
(define animal 'polarbaer)))
(define ocean
(make-environment
(define animal 'shark)))
The difference between this an MIT Scheme is that "make-environment", in MIT
Scheme, extends the current environment and in MzScheme it always extends a
R5RS environment.