[心得] clojure
上次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
推
05/22 02:15, , 1F
05/22 02:15, 1F
PLT 近期熱門文章
PTT數位生活區 即時熱門文章