How to evaluate lines in a racket

I am trying to figure out how to get the eval function to read a string and evaluate the contents inside the string.

I currently know that

> (eval '(+ 1 2)) 3 

but I'm not so good at using racquets. So at the moment I'm trying to make it so that I can do this:

 > (eval "(+ 1 2)") 3 

Any tips or links to useful resources would be appreciated.

+6
source share
1 answer

You want to use read along with open-input-string . For instance:

 -> (eval (read (open-input-string "(+ 1 2)"))) 3 

You can also use with-input-from-string :

 -> (with-input-from-string "(+ 1 2)" (lambda () (eval (read)))) 3 
+14
source

Source: https://habr.com/ru/post/914637/


All Articles