component

Serafeim Papastefanos 2022-04-26T22:09:43.727819Z

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 project

2022-04-26T22:13:41.491819Z

it 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

2022-04-26T22:14:14.011379Z

this is the instance of the defrecord, and it assocs in :connection when starting if there is no connection

Serafeim Papastefanos 2022-04-26T22:25:24.398059Z

So this is like checking if this.connection is not nil?

2022-04-26T22:26:06.156339Z

sure

Serafeim Papastefanos 2022-04-26T22:27:09.039359Z

Thanks! Is there somewhere that this is explained? I read the docs for defrecord but couldn't understand :/

seancorfield 2022-04-26T22:29:03.350479Z

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?

seancorfield 2022-04-26T22:30:05.205249Z

(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)

Serafeim Papastefanos 2022-04-26T22:32:42.604179Z

Thank you for the recommendation