-
-
Save Sose/6df4962cf02c5a10aba43559ad9f5519 to your computer and use it in GitHub Desktop.
This file contains 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
(ns kilppari.spec | |
(:require [clojure.spec.alpha :as s])) | |
(s/def ::type keyword?) | |
(s/def ::v any?) ;; ??? | |
(s/def ::argument | |
(s/keys | |
:req-un [::type ::v])) | |
;; I would like to say: if :type = :value then :v must be a number, or if :type = :variable, then :v must be a keyword | |
(s/def ::arguments (s/coll-of ::argument)) | |
(defn command? [x] | |
(case x | |
:move true | |
:turn true | |
:repeat true | |
false)) | |
(s/def ::command command?) | |
(s/def ::instruction (s/tuple ::command ::arguments)) | |
(s/def ::script (s/coll-of ::instruction)) |
This file contains 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
(def default-turtle-env {:x 90}) | |
(def default-script | |
;; move 10 | |
[[:move [{:type :value | |
:v 10}]] | |
;; turn x | |
[:turn [{:type :variable | |
:v :x}]] | |
;; repeat 10 | |
;; move x | |
;; end | |
[:repeat [{:type :value | |
:v 10} | |
{:type :value | |
:v [:move [{:type :variable :v :x}]]}]]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment