In this example (from here):
(defmethod event-msg-handler :chsk/recv
[{:as ev-msg :keys [?data]}]
(logf "Push event from server: %s" ?data)))
where ?data
is vector
, does the ?
have any purpose or signify something?
The question mark does not change the way that Clojure reads or evaluates the symbol. A symbol that contains a question mark is treated in exactly the same way by Clojure as a symbol that does not.
The use of the ? in the ?data symbol is therefore just a naming convention used by the author of the Sente library.
Generally punctuation in symbols is a naming convention. a trailing ?
usually indicates a predicate function or some boolean flag.
Examples in the core api are things like map?
and number?
. An example might look like this:
=> (filter number? [1 "foo" 2 :bar])
(1 2)
=> (remove number? [1 "foo" 2 :bar])
("foo" :bar)
=> (def debug? true)
(when debug? (println "Debugging")
a trailing !
generally indicates that some in place mutation is occuring, e.g
=>(def an-atom (atom 0))
=> @an-atom
0
=> (reset! an-atom 10)
=> @an-atom
10
However, some libraries do attach further meaning. For example cascalog uses leading ?
!!
and !
to indicate some differing properties of query output vars. See The Cascalog Docs for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With