Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

make-environment in PLT Scheme

27 views
Skip to first unread message

Alexander Schmidt

unread,
Dec 13, 2004, 8:13:59 PM12/13/04
to
Hi,

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.


Cláudio F. Gil

unread,
Dec 14, 2004, 7:03:56 AM12/14/04
to
Alexander Schmidt wrote:
> Hi,
>
> 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))

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".

Alexander Schmidt

unread,
Dec 14, 2004, 8:50:02 AM12/14/04
to

"Cláudio F. Gil" <cf...@esw.inesc-id.pt> wrote in message
news:32836kF...@individual.net...

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.


Jens Axel Søgaard

unread,
Dec 14, 2004, 10:49:03 AM12/14/04
to
Alexander Schmidt wrote:

>>>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

Cláudio F. Gil

unread,
Dec 14, 2004, 3:21:52 PM12/14/04
to
Alexander Schmidt wrote:

> 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.

0 new messages