Should we have a clojure.core/deref
pattern?
(m/match (atom {:visits 100})
@{:visits ?visits}
[:p "Visits: " ?visits])
;; => [:p "Visits: " 100]
so… syntax sugar for (m/pred #(satisfies? IDeref %) (m/app deref <thing>))
???
pros: it seems useful and convenient 🙂 cons: are there risks in conflating evaluation time with matching? I can’t think of any concrete risks here.
Yeah, something like that. I don’t know if there are any real cons apart from stealing clojure.core/deref
.
Which actually might be a bad idea.
Some folks may not realize that @
and clojure.core/deref
are the same thing.
I guess from a data perspective, one could argue that @
is not data, but FWIW I also think that the idea of promises/future things is not a Clojure only thing, and a pretty useful idea (laziness too).
m/app can do that right? Is it worth hanging onto @ for something custom?
any thoughts on what @
might otherwise mean?
Well for one thing, I might want to match the literal symbol clojure.core/deref. So maybe something funk would be bad
Yeah… We have the same “problem” with ~
.
At the same time, parsing ~
in a macro form specially is an uncommon but useful technique.
Just as a data point of 1 I have no problem quoting colliding symbols! 🙂
The fact that the Clojure reader expands @ does add a curveball, in that
@x
=== (clojure.core/deref x)
but I don’t see any immediate inconsistencies
Oh well '@x
means '(clojure.core/deref x)
doesn’t it? So either the operator would have to be smart or you can’t quote them like that :thinking_face: that does seem tricky!
i.e. ('clojure.core/deref ?x)
is how it should be treated, but that’s not what it is.
but really '@x
doesn’t make any sense anyhow sorry for the noise here I’m just trying to wrap my head around it! 🙂
> Just as a data point of 1 I have no problem quoting colliding symbols!
I agree. Thats what '
is there for.
'@x
is parsed as
'(clojure.core/deref x)
however this is not a problem because that is actually the form
(quote (clojure.core/deref x))
and meander respects quote
so theres not problem there.So
(match '(clojure.core/deref toast) '@toast true) ;; => true
and
(me/match '(clojure.core/deref toast) @toast true) ;; => true