-
-
Save ryoakg/1f1ac1d93c2c9c8167816dee344c0dde 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