~subsetpark/ec

ref: 3fcb736eaa84bebba6dd5dbb56d7fe8d030d5cf2 ec/src/print.janet -rw-r--r-- 392 bytes
3fcb736e — Zach Smith Add swap 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(use fugue)

(import /src/calc)

(defgeneric p
  [val] (describe val))

(defmethod p calc/Int
  [n] (string (n :value)))

(defmethod p calc/Float
  [n] (string (n :value)))

(defmethod p calc/Operation
  [o] (string (o :type)))

(defmethod p calc/Adverb
  [a] (string (a :type)))

(defmethod p calc/Vector
  [v]
  (let [inner (map p (v :data))]
    (string "[" (string/join inner " ") "]")))