https://stackoverflow.com/questions/6033006/demonstrate-first-class-Functions-in-this-simple-example/6033207#6033207" 关于另一个问题,有人说,Clojure idiom宁愿返回Nil,而不是像计划那样的空洞清单。 为什么如此?
和
(when (seq lat) ...)
instead of
(if (empty? lat)
() ...)
https://stackoverflow.com/questions/6033006/demonstrate-first-class-Functions-in-this-simple-example/6033207#6033207" 关于另一个问题,有人说,Clojure idiom宁愿返回Nil,而不是像计划那样的空洞清单。 为什么如此?
和
(when (seq lat) ...)
instead of
(if (empty? lat)
() ...)
我可以考虑几个原因:
http://www.ohchr.org。 在衣物中,无价值。 虽然(is这一空名单是一个价值,但只是一个空洞的清单。 区分两者在概念上和逻辑上往往非常有用。
www.un.org/Depts/DGACM/index_spanish.htm 符合《国际交易日志的,《国际交易日志》标本模型支持不提及。 而许多 Java亚普西人返回的意思是“无”或“未发现的价值”。 为了保证通用公平市价竞标的易用性,因此,用类似方式使用Nil是合理的。
<>Laziness——这里的逻辑非常复杂,但我的理解是,使用Nil“无名单”与Lucjure s相比更好。 由于Clojure是缺省功能性方案拟订语言,因此这种使用成为标准是合理的。 见http://clojure.org/lazy"rel=“nofollow noretinger”http://clojure.org/lazy,供作一些额外解释。
<>Falsiness> - It s convenient to use nil to mean “nothing” and also to mean "false” when written conditions Code that reviews Collection - so You can written Code as (if (some-map :some-key) ...
to test if ahmap includes a Value for a given key.
<>Performance 测试 n比审查清单,看看看它是否空洞,效率更高,因此采用这一格言作为标准,可提高性能。
请注意,在Clojure,仍有一些职能,确实是一份空洞清单。 例如:
(rest [1])
=> ()
This question on rest vs. next goes into some detail of why this is.....
还指出,收集类型和零类的结合是一种独一无二的做法,将一对一对一加一对一无二。 因此,Nil将空洞清单的异构体分类,同时代表虚假或“放任”价值。
甲胺是另一种常见的单一身份代表虚假价值观的语言:0、零、空洞。
http://www.honofclojure.com/“rel=“noretinger”>。 The Joy of Clojure
由于空洞收集像<代码>true在波兰州的情况中那样,你需要一个辅助器,以测试在收集过程中是否有任何东西。 感谢 衣着提供这种技术:
(seq [1 2 3]) ;=> (1 2 3) (seq []) ;=> nil
在其他特许经营中,如通用许可证,则空档号指nil
。 这被称为nil punning,只有在空洞清单不实的情况下才可行。 返回<代码>nil 这里是重新引入绝食的 clo。
自2006年以来 我将撰写一份答复。 (kuro的答复提供了所有信息,但可能太大)
seq
is just what everybody uses most of the time but empty?
is fine to its just (not (seq lat))
when
has only one branch this is spezially good if you want to have sideeffects. You don t have to use do
.See this example:
(if false () (do (println 1) (println 2) (println 3)))
页: 1
(when true (println 1) (println 2) (println 3))
不是这种分散,而是认为它更好读。
P.S.
职能不称为if-not
和 > 更经常的是<代码>(如果(不是真实的)
。
I ve been playing a bit with Clojure and so far is fairly impressed, but one thing that I keep running into is wierd error messages from Clojure. This comes in two forms: Java errors, like null ...
I m using Clojure and I need to run a small simulation. I have a vector of length n (n is usually between 10 and 100) that holds values. On each simulation round (maybe 1000 rounds together), one of ...
I am trying to use clojure to implement a "plugin" for some vendor supplied software. Here is a little background on the vendor supplied software. It expects me to implement a particular interface ...
I m getting my feet wet with Clojure, and trying to get used to functional programming. I ve been translating various imperative functions from other languages into their Clojure equivalents -- and ...
OK, no cheating now. No, really, take a minute or two and try this out. What does "positions" do? Edit: simplified according to cgrand s suggestion. (defn redux [[current next] flag] [(if flag ...
All, I want to create a function that takes a symbol representing a java method and applies it to some object: (user=> (defn f [m] (. "foo" (m))) When I execute this, I get a result much ...
I m looking to map a modestly-expensive function onto a large lazy seq in parallel. pmap is great but i m loosing to much to context switching. I think I need to increase the size of the chunk of work ...
Let s say I have a LazySeq of java.lang.Character like ( ! / \% 1 9 / . i \% $ i space ^@) How can I convert this to a String? I ve tried the obvious (String. my-char-seq) but ...