Hello can you explain what's the value of connection that's tested in the if in this example
(defrecord IdempotentDatabaseExample [host port connection]
component/Lifecycle
(start [this]
(if connection ; already started
this
(assoc this :connection (connect host port))))
(stop [this]
(if (not connection) ; already stopped
this
(do (.close connection)
(assoc this :connection nil)))))
it's from the readme of the projectit refers to the record field connection, and the idea there is you create an instance of the defrecord without specifying a value for :connection, so it is nil
this is the instance of the defrecord, and it assocs in :connection when starting if there is no connection
So this is like checking if this.connection is not nil?
sure
Thanks! Is there somewhere that this is explained? I read the docs for defrecord but couldn't understand :/
Clojure's docstrings are nearly all very brief and tend to assume you already know some basics about the language -- are you learning from any books, as you go?
(many people recommend Getting Clojure and/or Programming Clojure, perhaps followed by Clojure Applied -- you should find records are well-covered in books like those)
Thank you for the recommendation