[心得] clojure

看板PLT (程式語言與理論)作者 (dryman)時間12年前 (2012/05/21 09:38), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
上次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
文章代碼(AID): #1FkPoER6 (PLT)
文章代碼(AID): #1FkPoER6 (PLT)