Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify #lang for eval in Racket

Tags:

racket

I want to use a specific #lang in eval to provide it its semantics. However, eval itself does not appear to have a mechanism to specify the language, and passing in #lang does not seem to work.

like image 451
ckfinite Avatar asked Oct 24 '15 20:10

ckfinite


People also ask

What do you mean specify?

Definition of specify transitive verb. 1 : to name or state explicitly or in detail. 2 : to include as an item in a specification.

Could you please specify meaning?

To explicitly name something or state a particular detail, you specify that thing. So, when you have a craving for dessert and you send someone to the store to buy ice cream, you may want to specify a flavor. If you assign something for a particular purpose, this verb means that you specify.


1 Answers

You can use make-module-evaluator from racket/sandbox for that.

> (require racket/sandbox)
> (define evaluator (make-module-evaluator "#lang racket/base"))
> (evaluator '(+ 1 2))
3
> (evaluator "(+ 1 2)")
3
like image 163
Alex Knauth Avatar answered Sep 17 '22 14:09

Alex Knauth