Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!uunet!sytex!smcl
From: smcl@sytex.com (Scott McLoughlin)
Subject: Re: Making a set! clone in scheme - How to handle static scoping?
Message-ID: <PaFouc7w165w@sytex.com>
Sender: bbs@sytex.com
Organization: Sytex Access Ltd.
References: <HJSTEIN.94Oct23114631@sunset.huji.ac.il>
Date: Mon, 24 Oct 1994 01:28:48 GMT
Lines: 48

hjstein@sunset.huji.ac.il (Harvey J. Stein) writes:

> assigning it to various variables.  So, I was doing something like:
> 
> (set-list! '(a b c) (parse-data (get-data-line p)))
> 
> where get-data-line reads a line from a port, parse-data parses it
> into a list of input tokens, and (set-list! '(a b c) '(1 2 3)) is
> intended to be equivalent to (map set! '(a b c) '(1 2 3)), except that
>    (let ((a ())
>          (b ())
>          (c ()))
>       (set-list! '(a b c) '(1 2 3))))
> 
> It fails because a b & c are undefined in set-list!'s environment (or
> even worse, it will set variables other than the local versions of a b
> & c).

Howdy,
        Oh no, it's a bird, it's a plane, its... MULTIPLE-VALUE-BIND.
Eval probably works in the top-level lexical environment. This is
perfectly reasonable, since EVAL is not part of Scheme at all (if I
remember correctly).  Your implementation happens to support a 
Lisp-like EVAL, I suppose.
        In other words, the EVAL routine doesn't see local 
variables in the lexical scope of the _call_ to EVAL. It just
sees global variable and variables bound local to the EVAL'd
expression.
        I recently snagged some paper on Scheme multiple values, and
I believe it did mention the Scheme standard, so maybe MV's are on
the way (a bad thing, IMHO).
        In the meantime, consider the following alternatives:

        (LET* ((MV (expr-rtn-mv))
               (a (car MV)) (b (cadr MV)) ...)
             body...)
You could wrap this up in a macro, I presume. Even better, you
could pass a procedure that will use the variables, as in:

        (expr-rtn-mv arg1 arg2
           (lambda (a b c) body-using-a-b-c))

Whoops (make above text read "use the values"). Good luck.

=============================================
Scott McLoughlin
Conscious Computing
=============================================
