How to eval strings in racket

后端 未结 1 957
清歌不尽
清歌不尽 2021-02-20 15:54

I\'m trying to understand how to get the eval function to read a string and evaluate the content that\'s inside the string.

Currently I know that

> (         


        
相关标签:
1条回答
  • 2021-02-20 16:54

    You want to use read together with open-input-string. Like so:

    -> (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
    
    0 讨论(0)
提交回复
热议问题