Created
April 2, 2016 10:10
-
-
Save ochronus/8b3ffa32eeb6c3d65c330b1322ccd294 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn bf-interpreter [program-code] | |
(loop [cells [0N], current-cell 0, instruction-pointer 0] | |
(condp = (get program-code instruction-pointer) | |
\+ (recur (update-in cells [current-cell] inc) current-cell (inc instruction-pointer)) | |
\- (recur (update-in cells [current-cell] dec) current-cell (inc instruction-pointer)) | |
\. (do | |
(print (char (nth cells current-cell))) | |
(recur cells current-cell (inc instruction-pointer))) | |
\, (let [ch (.read System/in)] | |
(recur (assoc cells current-cell ch) current-cell (inc instruction-pointer))) | |
(recur cells current-cell (inc instruction-pointer))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment