Created
April 26, 2020 01:05
-
-
Save belmarca/d225ac1cca13f46d01528fead40200c3 to your computer and use it in GitHub Desktop.
Hooking gambit's ##wr.
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
;; cb.ss | |
(defstruct ugly-struct (a b c)) | |
(defstruct wonderful-struct (a b c)) | |
(defmethod {:wr wonderful-struct} | |
(lambda (self we obj) | |
(with ((wonderful-struct a b c) self) | |
(##wr-str we "π¦<") | |
(##wr-str we " πππ ") | |
(##wr-str we (string-append | |
"a: " (number->string a) | |
" b: " (number->string a) | |
" c: " (number->string a))) | |
(##wr-str we " πππ ") | |
(##wr-str we ">π¦")))) | |
(def us (ugly-struct 1 2 3)) | |
(def ws (wonderful-struct 1 2 3)) | |
(def (gerbil-##wr we obj) | |
(let (wr (find-method (object-type obj) ':wr)) | |
(if wr | |
(wr obj we obj) | |
(##default-wr we obj)))) | |
(##wr-set! gerbil-##wr) | |
;; > us | |
;; #<ugly-struct #2> | |
;; > ws | |
;; π¦< πππ a: 1 b: 1 c: 1 πππ >π¦π¦< πππ a: 1 b: 1 c: 1 πππ >π¦ | |
;; > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like in current Gerbil, the method has arguments
(self we)
not(self we obj)
βindeed theobj
was redundant.