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

查看:23
本文介绍了当我将参数传递给 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天全站免登陆