guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: modify environments to make sandboxes


From: Jon Wilson
Subject: Re: modify environments to make sandboxes
Date: Tue, 27 Jun 2006 23:13:12 -0500
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050324)

Hi all,
How about having the ability to capture the current lexical environment and use it as an environment for eval? Something like call/cc, but I guess call/env. In essence, this would make environments useful as first class objects (perhaps).

(define my-env #f)

(let ((a 0) (b 1) (c 2))
  (call/env (lambda (x) (set! my-env x))))

(eval '(begin
        (display a) (newline)
        (display b) (newline)
        (display c) (newline)
        (display my-env) (newline))
      my-env)

>> prints:
0
1
2
#<environment 0xDEADBEEF>


Perhaps an unlet would also be useful. This would create a lexical environment in which several variables were unbound.

(unlet (eval read load)
 (call/env (lambda (x) (set! my-env x))))

(eval '(eval '(+ 1 2)) my-env)
=>
#error

Hmmm, perhaps this idea (unlet) couldn't work in any kind of a sensible, simple, lexical scoping system. Maybe unlet could just set the variables given to it to #<unspecified> or #f or something.

So, which extant language feature have I overlooked that provides more or less exactly this? :)

Regards,
Jon

Mildred wrote:
Hi,

I'm new to this mailing list and also new to the scheme language ...
I'm used to Lua but I try to search about functionnal programming, and
I found scheme. It looks like a good language but before using it in my
projects I would like to know if tere is an easy way to create
sandboxes.

In lua, it is easy, you create a table containing functions ... and the
table can be made environment for a function. So, you can easily create
secure sandboxes by loading lua code from file and changing the
environment of the loaded code.

I do not know how to do that in scheme. Apparetly the function
null-environment can return an environment and eval can evaluate some
code in an environment. But the question is how to define a variable in
an environment and also how to undefine a variable that you don't want
to appear.
I didn't found anything about modifying an environment. Is it
possible ? If not, why not ? and is it possible to create sandboxes ?
Thanks

Mildred





reply via email to

[Prev in Thread] Current Thread [Next in Thread]