Clojure中read-string和load-string的区别 [英] Difference between read-string and load-string in Clojure

查看:123
本文介绍了Clojure中read-string和load-string的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码工作后,用load-string替换read-string。这是好的代码工作,但我想知道为什么。两个clojure函数之间的区别是什么?

I have some code which works after replacing read-string with load-string. It is good that the code works, but I would like to know why. What is the difference between the two clojure functions?

推荐答案

使用load-string顺序读取和评估
string

Use load-string to sequentially read and evaluate the set of forms contained in the string

使用read-string从字符串s中读取一个对象

Use read-string to read one object from the string s

引自 Clojure API

string会将你的字符串作为一个Clojure表达式,read-string接受这个字符串并返回它作为找到的数据结构,在这种情况下可能是一个表达式。

Load-string will evaluate your string as a Clojure expression, and read-string takes the string and returns it as the found data structure, in which case might be an expression.

Protip: load-string(+ 1 2) eval(read-string(+ 1 2))你的结果相同,这是3}

{Protip: load-string(+ 1 2) and eval(read-string(+ 1 2)) will give you the same result, which is 3}

这篇关于Clojure中read-string和load-string的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆