This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-26
Channels
- # babashka (7)
- # beginners (85)
- # calva (39)
- # cider (3)
- # clara (1)
- # clj-kondo (10)
- # clojure (194)
- # clojure-europe (36)
- # clojure-madison (2)
- # clojure-nl (13)
- # clojure-spec (11)
- # clojure-uk (2)
- # clojurescript (17)
- # community-development (5)
- # component (9)
- # conjure (4)
- # core-async (3)
- # cursive (32)
- # data-science (26)
- # datomic (31)
- # graalvm (22)
- # holy-lambda (31)
- # honeysql (7)
- # introduce-yourself (1)
- # jobs (9)
- # jobs-rus (1)
- # lsp (3)
- # malli (9)
- # off-topic (54)
- # pathom (27)
- # pedestal (6)
- # portal (1)
- # re-frame (4)
- # releases (1)
- # remote-jobs (1)
- # sci (3)
- # shadow-cljs (4)
- # spacemacs (13)
- # vim (14)
- # xtdb (3)
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?
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