Last active
January 5, 2021 22:10
-
-
Save shinmuro/9338262 to your computer and use it in GitHub Desktop.
Clojure deftype that has mutable field and setter method sample.
This file contains hidden or 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
(defprotocol IEditName | |
(get-name [this]) | |
(set-name! [this val])) | |
(deftype PersonName [^:volatile-mutable lname] | |
IEditName | |
(get-name [this] (. this lname)) | |
(set-name! [this val] (set! lname val))) | |
(def pname (PersonName. "hoge")) | |
;=> #'user/pname | |
(set-name! pname "fuge") | |
;=> "fuge" | |
(get-name pname) | |
;=> "fuge" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@shinmuro Have a look at this gist live with KLIPSE http://tinyurl.com/cljs-mutable-klipse