"Unbound" clojure 函数中的变量



我正在编写一个函数来解析IRC RFC2813消息到它们的组成部分。这包括两个函数,一个用于通过正则表达式拆分消息,另一个用于修改返回以处理某些特殊情况。

(let [test-privmsg ":m@m.net PRIVMSG #mychannel :Hiya, buddy."])
(defn ircMessageToMap [arg]
"Convert an IRC message to a map based on a regex"
(println (str "IRCMapifying " arg))
(zipmap [:raw :prefix :type :destination :message]
(re-matches #"^(?:[:](S+) )?(S+)(?: (?!:)(.+?))?(?: [:](.+))?$"
arg
)
)
)
(defn stringToIRCMessage [arg]
"Parses a string as an IRC protocol message, returning a map"
(let [r (doall (ircMesgToMap arg))])
(println (str "Back from the wizard with " r))
(cond
;Reformat PING messages to work around regex shortcomings
(= (get r :prefix) "PING") (do
(assoc r :type (get r :prefix))
(assoc r :prefix nil)
)
;Other special cases here
:else r)
)

我遇到的问题是stringToIRCMessage函数似乎没有实现ircMesgToMap的返回值。如果我评估(stringToIRCMessage test-privmsg)println语句给我:

Back from the wizard with Unbound: #'irc1.core/r

..但是ircMessageToMap的"IRCMapifying"结果事先出现在控制台上,表明它已正确评估。

doall是试图强制在函数中间实现结果 - 它没有任何效果。

我应该如何重写这个stringToIRCMessage函数以使r变量可用?

括号在您的let陈述中是错误的。

应如下所示:

(let [r (doall (ircMesgToMap arg)) ]
(println (str "Back from the wizard with " r))
(cond
;Reformat PING messages to work around regex shortcomings
(= (get r :prefix) "PING") (do
(assoc r :type (get r :prefix))
(assoc r :prefix nil)
)
;Other special cases here
:else r))

最新更新