Skip to content

Instantly share code, notes, and snippets.

@shinmuro
Last active January 5, 2021 22:10
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shinmuro/9338262 to your computer and use it in GitHub Desktop.
Save shinmuro/9338262 to your computer and use it in GitHub Desktop.
Clojure deftype that has mutable field and setter method sample.
(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"
@viebel
Copy link

viebel commented Apr 22, 2016

@shinmuro Have a look at this gist live with KLIPSE http://tinyurl.com/cljs-mutable-klipse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment