How do I define a subsystem in a schema?

I am just hacking the Scheme (mit-schema) and I just figured out how you change the environment so that the "+" becomes the symbol of the equivalent operator procedure "-".

Example

(environment-define user-initial-environment '+ -)
(eval (+ 3 2) user-initial-environment)
=> 1

      

I'm just wondering if there was an easy way to deal with environments as variables, so when I inject the environment into eval, for example

(eval <exp> user-initial-environment) 

      

I don't need to use "user-initial-environment". So I can "play" in different environments for the function.

(eval <exp> env) 

      

Where env is some predefined environment tied to my env variable.

+2


source to share


1 answer


The corresponding MIT Scheme documentation page on top-level environments can be instructive - you can either extend an existing top-level environment (c extend-top-level-environment

) or create a new one from scratch (c make-top-level-environment

).



However, for evaluating anything other than the most trivial expressions, it may be useful to extend either system-global-environment

or user-initial-environment

(cf 13.2: Environment Variables )

+3


source







All Articles