For Programmers: Free Programming Magazines  


Home > Archive > Scheme > December 2004 > make-environment in PLT Scheme









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author make-environment in PLT Scheme
Alexander Schmidt

2004-12-14, 3:58 am

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

2004-12-14, 9:08 am

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

2004-12-14, 4:09 pm


"Clįudio F. Gil" <cfgi@esw.inesc-id.pt> wrote in message
news:32836kF3gho7iU1@individual.net...
> Alexander Schmidt wrote:
>
> 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.
>
get[color=darkred]
>
> 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.


Jens Axel Sųgaard

2004-12-14, 4:09 pm

Alexander Schmidt wrote:
[color=darkred]
[color=darkred]

Your lecture notes probably define environments before giving the
above examples.

Are the lecture notes online somewhere?

--=20
Jens Axel S=F8gaard

Clįudio F. Gil

2004-12-14, 9:01 pm

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







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com