Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图了解如何让 eval 函数读取字符串并评估字符串内的内容。
目前我知道
> (eval '(+ 1 2)) 3
但我对球拍的使用并不了解。所以目前我正试图得到它,以便我可以做到这一点:
> (eval "(+ 1 2)") 3
任何有用资源的建议或链接将不胜感激。
您想read与open-input-string. 像这样:
read
open-input-string
-> (eval (read (open-input-string "(+ 1 2)"))) 3
您还可以使用with-input-from-string:
with-input-from-string
-> (with-input-from-string "(+ 1 2)" (lambda () (eval (read)))) 3