如何将字符串作为 clojure 表达式求值?
我怎样才能得到类似以下内容的东西?:
(evaluate-text "(+ 1 2)") ; resolves to 3
How would I get something similar to the following?:
(evaluate-text "(+ 1 2)") ; resolves to 3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能根本不需要这样做。宏和 fns 使这种事情在 99% 的情况下变得不必要。这是非常脆弱的,如果这些字符串来自用户输入等,则可能不安全。
You probably shouldn't ever need to do this. Macros and fns make this kind of thing unnecessary 99% of the time. This is quite brittle, and can be unsafe if these strings are coming from user input, and so on.
它必须有多相似? Clojure 的
eval
适用于列表,因此:How similar does it have to be? Clojure's
eval
works on lists, so: