作者dryman (dryman)
看板PLT
标题[心得] clojure
时间Mon May 21 09:38:19 2012
上次fp聚会我会後有写一点点clojure的demo
其中一个是算DFA,当时说要上传不过忘记了orz
程式如下:
(def dfa
{:start :a,
:delta
{:a {0 :b,
1 :c}
:b {0 :a,
1 :b}
:c {0 :a,
1 :c}}
:accept #{:c :b}})
(defn process-dfa [dfa lst
]
(loop [state
(dfa
:start), lst lst
]
(if (seq lst
)
(recur (((dfa
:delta) state
) (first lst
))
(next lst
))
((dfa
:accept) state
))))
(process-dfa dfa
[0 1 0 0 1])
===> :b ; accepted
(process-dfa dfa
[0 1 0 0 1 0])
===> nil ; rejected
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.109.22.88
1F:推 godfat:感谢! 05/22 02:15