Re: converting dynamic to lexical scope

From: Jim Newton (jimka_at_rdrop.com)
Date: 12/19/04


Date: Sun, 19 Dec 2004 21:42:24 +0100

In SKILL there is a function theEnvironment
which returns the current environment object.
such an object can be passed to the set function,
as well as other functions such as eval.

This can be done as follows:

(defmacro vsetq ( vars vals)
    `(vset ',vars ,vals (theEnvironment)))

(defun vset ( vars vals env)
    (cond
      ((null vars) nil)
      ((atom vars)
       ;; set the variable in the given environment
       (set vars vals env))
      (t
       (vset (car vars) (car vals) env)
       (vset (cdr vars) (cdr vals) env))))

I have seen that common lisp has environment
objects, but I have not yet figured out how
to get the current environment object nor
how to do setting and evaluating using a given
environment. Is it possible?

-jim

Jim Newton wrote:
> sorry, a little error in the vset function,
> it should call vset, not vsetq.
>
>
>
>> (defun vset ( vars vals)
>> (cond
>> ((null vars) nil)
>> ((atom vars)
>> (set vars vals))
>> (t
>> (vset (car vars) (car vals))
>> (vset (cdr vars) (cdr vals)))))
>>
>> (defmacro vsetq ( vars vals)
>> `(vset ',vars ,vals))
>>
>