-
-
Save Sose/32aa813eea3004ecf7c3176b8b7c5a68 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] | |
[clojure.test.check.generators :as gen])) | |
(s/def :command/v (s/or :variable keyword? | |
:value number?)) | |
;(s/def :command/type #{:move :turn :repeat :pen :let :function :call}) | |
(defmulti instruction (fn [[command _]] command)) | |
(defmethod instruction :move [_] | |
(s/tuple #{:move} :command/v)) | |
(defmethod instruction :turn [_] | |
(s/tuple #{:turn} :command/v)) | |
(defmethod instruction :repeat [_] | |
(s/tuple #{:repeat} :command/v :command/script)) | |
(defmethod instruction :pen [_] | |
(s/tuple #{:pen} #{:up :down})) | |
(defmethod instruction :let [_] | |
(s/tuple #{:let} keyword? number?)) | |
(defmethod instruction :function [_] | |
(s/tuple #{:function} keyword? (s/coll-of keyword?) :command/script)) | |
(defmethod instruction :call [_] | |
(s/tuple #{:call} keyword? number?)) | |
(s/def :command/instruction (s/multi-spec instruction (fn [genv _tag] genv))) | |
(s/def :command/start (s/tuple #{:start} number? number? number?)) | |
;; a (sub)script is a vector of instructions | |
(s/def :command/script (s/coll-of :command/instruction)) | |
;; main scripts must have a "start instruction" at the beginning | |
(s/def :command/main-script (s/cat :start :command/start | |
:script (s/* :command/instruction))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment