如何解决有人知道Clojure中的递归BNF吗?
Clojure不使用for
语句,但使用递归。这是Clojure中for
循环的示例:
;; looping is recursive in Clojure,the loop construct is a hack so that
;; something like tail-recursive-optimization works in clojure.
user=> (defn my-re-seq [re string]
"Something like re-seq"
(let [matcher (re-matcher re string)]
(loop [match (re-find matcher) ;loop starts with 2 set arguments
result []]
(if-not match
result
(recur (re-find matcher) ;loop with 2 new arguments
(conj result match))))))
#'user/my-re-seq
user=> (my-re-seq #"\d" "0123456789")
["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"]
有人可以帮助Clojure进行BNF
递归吗?
以下是python中for语句的BNF
的示例:
for_stmt ::= "for" target_list "in" expression_list ":" suite
["else" ":" suite]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。