ckfinite
ckfinite

Reputation: 437

Specify #lang for eval in 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.

Upvotes: 8

Views: 171

Answers (1)

Alex Knauth
Alex Knauth

Reputation: 8373

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

Upvotes: 9

Related Questions