Below you will find pages that utilize the taxonomy term “计算理论 clojure”
Posts
Clojure 模拟图灵机
最近在读《计算的本质:深入剖析程序和计算机 》,一本关于计算理论的小册子,使用 Ruby 语言介绍计算理论,第一步分从状态机开始直接,DFA/NFA、自动下推机直到图灵机,并且每个小章节都给出了代码例子。第二部分开始介绍 lambda 、丘奇数、停机问题等函数式编程的基础知识,挺好玩的一个阅读过程。
作者提供的 Ruby 代码在这里。
我试着用 Clojure 重新实现了里面的图灵机模拟器的例子,
(ns cljcomputionbook.tm (:require [clojure.string :as cs])) ;;磁带 (defrecord Tape [left middle right blank] Object (toString [tape] (pr-str tape))) (defmethod print-method Tape [tape writer] (.write writer (format "#<Tape %s(%s)%s>" (cs/join (:left tape)) (:middle tape) (cs/join (:right tape))))) (defn write [{:keys [left right blank]} ch] (Tape. left ch right blank)) (defmulti move-head (fn [tape direction] direction)) (defmethod move-head :left [{:keys [left middle right blank]} _] (Tape.