关于教程中Learn Clojure - Functions 一节中的习题,第四题的解答

41 views
Skip to first unread message

Dervish

unread,
Sep 7, 2018, 12:03:08 PM9/7/18
to CN-Clojure

4) Define a function do-nothing which takes a single argument x and returns it, unchanged.

(defn do-nothing [x] ___)
In Clojure, this is the identity function. By itself, identity is not very useful, but it is sometimes necessary when working with higher-order functions.

(source identity)

第四题的题目是这样的,似乎没有太看懂,

答案是这样的吗?
(defn do-nothing [x] x)

dennis zhuang

unread,
Sep 8, 2018, 7:07:21 AM9/8/18
to cn-cl...@googlegroups.com
你的回答是对的, identity 也是一样的定义方式,只是多了个 static 标签

(defn identity
 "Returns its argument."
 {:added "1.0"
  :static true}
 [x] x)

不过这个标签现在也是没有必要的,只是 1.3.0 版本上的插曲。



Dervish <dervi...@gmail.com> 于2018年9月8日周六 上午12:03写道:
--
中文社区博客:http://blog.clojure.cn/
中文问答网站:http://ask.clojure.cn/
中文邮件列表:https://groups.google.com/d/forum/cn-clojure?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛上的“CN-Clojure”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到cn-clojure+...@googlegroups.com
要发帖到此群组,请发送电子邮件至cn-cl...@googlegroups.com
访问此群组:https://groups.google.com/group/cn-clojure
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/cn-clojure/f66796cf-c4c7-40c1-bbf6-771c39488841%40googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout


--
庄晓丹
Email:        killm...@gmail.com
Site:           http://fnil.net

不学习,毋宁死

Dervish

unread,
Sep 9, 2018, 10:34:01 PM9/9/18
to CN-Clojure
还有个问题是这种冒号开头的  :added 是一个类似于变量的东西么?

在 2018年9月8日星期六 UTC+8下午7:07:21,dennis写道:
你的回答是对的, identity 也是一样的定义方式,只是多了个 static 标签

(defn identity
 "Returns its argument."
 {:added "1.0"
  :static true}
 [x] x)

不过这个标签现在也是没有必要的,只是 1.3.0 版本上的插曲。



Dervish <dervi...@gmail.com> 于2018年9月8日周六 上午12:03写道:

4) Define a function do-nothing which takes a single argument x and returns it, unchanged.

(defn do-nothing [x] ___)
In Clojure, this is the identity function. By itself, identity is not very useful, but it is sometimes necessary when working with higher-order functions.

(source identity)

第四题的题目是这样的,似乎没有太看懂,

答案是这样的吗?
(defn do-nothing [x] x)

--
中文社区博客:http://blog.clojure.cn/
中文问答网站:http://ask.clojure.cn/
中文邮件列表:https://groups.google.com/d/forum/cn-clojure?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛上的“CN-Clojure”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到cn-clojure+unsubscribe@googlegroups.com

要发帖到此群组,请发送电子邮件至cn-cl...@googlegroups.com
访问此群组:https://groups.google.com/group/cn-clojure
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/cn-clojure/f66796cf-c4c7-40c1-bbf6-771c39488841%40googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout

dennis zhuang

unread,
Sep 9, 2018, 10:37:27 PM9/9/18
to cn-cl...@googlegroups.com
这是 metadata,added 表示 API 添加的 clojure 版本号,类似 javadoc 里 @since。这类问题建议先阅读下 clojure 的文档或者入门书籍。

Dervish <dervi...@gmail.com> 于2018年9月10日周一 上午10:34写道:
还有个问题是这种冒号开头的  :added 是一个类似于变量的东西么?

在 2018年9月8日星期六 UTC+8下午7:07:21,dennis写道:
你的回答是对的, identity 也是一样的定义方式,只是多了个 static 标签

(defn identity
 "Returns its argument."
 {:added "1.0"
  :static true}
 [x] x)

不过这个标签现在也是没有必要的,只是 1.3.0 版本上的插曲。



Dervish <dervi...@gmail.com> 于2018年9月8日周六 上午12:03写道:

4) Define a function do-nothing which takes a single argument x and returns it, unchanged.

(defn do-nothing [x] ___)
In Clojure, this is the identity function. By itself, identity is not very useful, but it is sometimes necessary when working with higher-order functions.

(source identity)

第四题的题目是这样的,似乎没有太看懂,

答案是这样的吗?
(defn do-nothing [x] x)

--
中文社区博客:http://blog.clojure.cn/
中文问答网站:http://ask.clojure.cn/
中文邮件列表:https://groups.google.com/d/forum/cn-clojure?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛上的“CN-Clojure”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到cn-clojure+...@googlegroups.com

要发帖到此群组,请发送电子邮件至cn-cl...@googlegroups.com
访问此群组:https://groups.google.com/group/cn-clojure
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/cn-clojure/f66796cf-c4c7-40c1-bbf6-771c39488841%40googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout


--
庄晓丹
Email:        killm...@gmail.com
Site:           http://fnil.net

不学习,毋宁死

--
中文社区博客:http://blog.clojure.cn/
中文问答网站:http://ask.clojure.cn/
中文邮件列表:https://groups.google.com/d/forum/cn-clojure?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛上的“CN-Clojure”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到cn-clojure+...@googlegroups.com

要发帖到此群组,请发送电子邮件至cn-cl...@googlegroups.com
访问此群组:https://groups.google.com/group/cn-clojure

Dervish

unread,
Sep 10, 2018, 12:47:25 AM9/10/18
to cn-cl...@googlegroups.com
好的, 十分感谢。

dennis zhuang <killm...@gmail.com> 于2018年9月10日周一 上午10:37写道:
Reply all
Reply to author
Forward
0 new messages