当我传递参数到一个Clojure符号会发生什么? [英] What happens when I pass arguments to a Clojure symbol?

查看:128
本文介绍了当我传递参数到一个Clojure符号会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做:

('a 'b 'c)

我得到这个:

c

为什么?

推荐答案

链接Hauleth发布的是一个很好的概述符号,但你的问题的答案是调用一个符号作为一个函数相当于在第一个参数中查找该符号。

The link Hauleth posted is a good overview to symbols but the answer to your question is that calling a symbol as a function is equivalent to looking that symbol up in the first argument.

('a 'b)

相当于

(get 'b 'a)

get的文档显示可以传递可选的第三个参数作为默认值。在你的例子中,'c被当作默认值,并返回,因为'b不是一个映射,'a不能被找到。

The documentation for get shows that you can pass an optional third argument as the default. In your example 'c is treated as the default and returned since 'b is not a map and 'a can't be found.

这篇关于当我传递参数到一个Clojure符号会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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