开发者

Closure's (apply str) questions?

With closure

(开发者_开发问答apply str [\a \b])

and

(apply str '(\a \b))

returns "ab".

(apply str (\a \b))

returns an error.

Why is that?


Because (\a \b) means "call the function \a with an argument of \b", and since the character \a is not a function, it fails. Note the difference in the following:

user=> (+ 1 2 3)
6
user=> '(+ 1 2 3)
(+ 1 2 3)

As a general rule, if you want to write a literal sequence, use a vector instead of a quoted list since the quote will also stop evaluation of the parts inside the list, e.g.:

user=> [(+ 1 2) (+ 3 4)]
[3 7]
user=> '((+ 1 2) (+ 3 4))
((+ 1 2) (+ 3 4))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜