Skip to content

Instantly share code, notes, and snippets.

@Sose

Sose/spec.cljs Secret

Last active May 25, 2021 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sose/6df4962cf02c5a10aba43559ad9f5519 to your computer and use it in GitHub Desktop.
Save Sose/6df4962cf02c5a10aba43559ad9f5519 to your computer and use it in GitHub Desktop.
(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))
(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