Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't Scheme support first class environments?
    primarykey
    data
    text
    <p>I've been reading through SICP (Structure and Interpration of Computer Programs) and was really excited to discover this wonderful special form: "make-environment", which they demonstrate to use in combination with eval as a way of writing modular code (excerpt from section 4.3 on "packages"):</p> <pre><code>(define scientific-library (make-environment ... (define (square-root x) ...))) </code></pre> <p>They then demonstrate how it works with</p> <pre><code>((eval 'square-root scientific-library) 4) </code></pre> <p>In their example, they then go on to demonstrate <em>exactly</em> the usage that I would want - an elegant, minimalist way of doing the "OO" style in scheme... They "cons" together a "type", which is actually what was returned by the "make-environment" special form (i.e. the vtable), and an arg ("the state")... </p> <p>I was so excited because this is <em>exactly</em> what I've been looking for as a way to do polymorphic dispatch "by symbol" in Scheme without having to write lots of explicit code or macros.</p> <p>i.e. I want to create an "object" that has, say, <em>two</em> functions, that I call in different contexts... but I don't want to refer to them by "car" and "cdr", I want to both <em>declare</em> and <em>evaluate</em> them by their symbolic names.</p> <p>Anyway, when I read this I couldn't wait to get home and try it.</p> <p>Imagine my disappointment then when I experienced the following in both PLT Scheme and Chez Scheme:</p> <pre><code>&gt; (make-environment (define x 3)) Error: invalid context for definition (define x 3). &gt; (make-environment) Error: variable make-environment is not bound. </code></pre> <p>What happened to "make-environment" as referenced in SICP? It all seemed so elegant, and exactly what I want, yet it doesn't seem to be supported in any modern Scheme interpreters?</p> <p>What's the rationale? Is it simply that "make-environment" has a different name?</p> <p><strong>More information found later</strong></p> <p>I took at look at the online version:</p> <p><a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-28.html#%_sec_4.3" rel="nofollow noreferrer">http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-28.html#%_sec_4.3</a></p> <p>I was reading was the first edition of SICP. The second edition appears to have replaced the discussion on packages with a section on non-deterministic programming and the "amp" operator.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload