Skip to content

Commit 26cb647

Browse files
committed
Records
1 parent e5003e7 commit 26cb647

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/basilisp/pprint.lpy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,14 @@
673673
(print-meta obj)
674674
(print-map "{" "}" obj))
675675

676+
(defmethod simple-dispatch basilisp.lang.interfaces/IRecord
677+
[obj]
678+
(print-meta obj)
679+
(let [prefix (str "#" (.-__qualname__ (python/type obj)) "{")]
680+
(print-map prefix "}" (into {} obj))))
681+
682+
(prefer-method simple-dispatch basilisp.lang.interfaces/IRecord basilisp.lang.interfaces/IPersistentMap)
683+
676684
(defmethod simple-dispatch python/dict
677685
[obj]
678686
(print-map "#py {" "}" (.items obj)))

tests/basilisp/test_pprint.lpy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@
216216
(deftest pprint-var-test
217217
(is (= "#'basilisp.core/map\n" (with-out-str (pprint/pprint #'map)))))
218218

219+
(defrecord Point [x y z])
220+
221+
(deftest pprint-record-test
222+
(is (= "#Point{:x 1 :y 2 :z 3}\n"
223+
(with-out-str
224+
(binding [pprint/*print-sort-keys* true]
225+
(pprint/pprint (->Point 1 2 3)))))))
226+
219227
(deftest pprint-ideref-test
220228
(testing "delay"
221229
(let [d (delay :delayed)]

0 commit comments

Comments
 (0)