(defn explain-defcon-level [exercise-term]
(case exercise-term
:fade-out :you-and-what-army
:double-take :call-me-when-its-important
:round-house :o-rly
:fast-pace :thats-pretty-bad
:cocked-pistol :sirens
:say-what?))
Run Code Online (Sandbox Code Playgroud)
如果我理解正确的话,通常键有冒号而值没有。这里的目的是什么?谢谢。
以 开头的单词:
是关键字。关键字在某些语言中充当已知值,如枚举。您还可以像在 Python 或 JavaScript 中一样使用字符串,但关键字有一些很好的功能。
在这种情况下,如果函数接收例如已知关键字:round-house
,它将返回已知值:o-rly
。其他一些代码反过来知道什么:o-rly
意思。如果代码调用,您也可以使用字符串explain-defcon-level
如果调用的代码期望它返回字符串
关键词:
(def m {:abba 1 :beef 2}) .. (:abba m) => 1
(name :foo) => "foo"
(keyword "bar") => :bar