[英]What's the purpose of the :printed keyword in this Clojure doto macro example?
I've been looking at this Clojure doto macro example from ClojureDocs , and I can't figure out what the purpose of the :printed
keyword in the final println
. 我一直在寻找这样的Clojure 从ClojureDocs多托宏示例 ,我想不出什么目的
:printed
关键字在最后println
。
When I enter the example in a REPL, it prints out the HashMap as I would expect, just with a :printed
displayed after the HashMap: 当我在REPL中输入示例时,它会按照我的预期打印出HashMap,只需使用
:printed
在HashMap之后显示:
user=> (doto (java.util.HashMap.) (.put "a" 1) (.put "b" 2) (println :printed))
#<HashMap {b=2, a=1}> :printed
{"b" 2, "a" 1}
I figured println
needed a placeholder so that it knows to wait for something coming from the doto
macro. 我认为
println
需要一个占位符,以便它知道等待来自doto
宏的东西。 So I tried seeing what I'd get if I omitted :printed
: 所以如果我省略的话,我试着看看我会得到什么
:printed
:
user=> (doto (java.util.HashMap.) (.put "a" 1) (.put "b" 2) (println))
#<HashMap {b=2, a=1}>
{"b" 2, "a" 1}
This one prints the same thing, but makes the HashMap without a :printed
alongside it. 这个打印相同的东西,但使HashMap没有
:printed
它旁边。 Given this result, shouldn't the doto
example give something like this: 鉴于此结果,
doto
示例不应该给出这样的结果:
#<HashMap {b=2, a=1}>
{"b" 2, "a" 1} :printed
What is the :printed
keyword doing? 什么是
:printed
关键字在做什么?
:printed
simply adds " :printed" to the string printed by println
. :printed
只是将“:printed”添加到println
打印的字符串中。 It does not affect the hash-map. 它不会影响哈希映射。
(println "Bingo" :printed)
=> Bingo :printed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.