Does โno matching ctorโ indicate a constructor w/ the same argument length doesnโt exist or also check the types as well?
can be either
Tangent from my prior question yesterday, I realized I could probably build myself the aliasing system I might want. So I'm still thinking about this, but as I've been struggling to figure out how to structure my Specs for entities, what name to give them, and what names to give my keys, I think this is a potentially interesting option:
(def key-ns
(atom {}))
(defn defkey
[alias keyns]
(swap! key-ns assoc (str alias) (str keyns)))
(set! *default-data-reader-fn*
(fn[tag-sym value]
(when (.startsWith (str tag-sym) "key")
(if (map? value)
(let [tag-key-str (second (re-find #"key:(.*)" (name tag-sym)))]
(if-let [tag-key (@key-ns tag-key-str)]
(reduce (fn[acc [k v]]
(if (qualified-keyword? k)
(assoc acc k v)
(assoc acc (keyword tag-key (name k)) v)))
{} value)
(throw (ex-info (str "No keyword namespace defined for " value) {}))))
(let [ns (namespace value)
na (name value)]
(if-let [k (@key-ns (str (or ns na)))]
(keyword (name k) na)
(throw (ex-info (str "No keyword namespace defined for " value) {}))))))))
Now with this, I can nicely define entities and entity spec with logical namespaces for my Specs and keywords, which are not tied to the physical code namespace they happen to be defined in:
(defkey 'person 'com.myorg.app.person)
(s/def #key person/name
string?)
(s/def #key person/address
string?)
(s/def #key person
(s/keys :req [#key person/name
#key person/address]))
#key:person {:name "John Doe"
:address "222 2nd Ave., New York, New York, USA"
:some/other 100}
It seems like youโve just recreated aliases, namespace map syntax
Aliases are the right answer to this, they just have the downside right now of requiring real loadable namespaces
If I know that a thing is a symbol, is there a way to get the metadata of the var pointed to by the symbol? Something like
(when (symbol? x)
(meta (var (??? x))))
@vale resolve
thanks!
What is the most elegant way to turn
[{:company "A" :accounts [{:name "A"} {:name "B"} {:name "C"}]} ...]
into
[{:company "A" :account {:name "A"}} {:company "A" :account {:name "B"}} ...]
?(for [{:keys [:company :accounts]} [{:company "A" :accounts [{:name "A"} {:name "B"} {:name "C"}]}]
account accounts]
{:company company
:account account})
Hmm. Thanks! I was hoping for something more elegant (maybe something as "obscure" as juxt
) that could be used, but I guess that'll do fine then.
I don't see how it can be more elegant than this to be honest ;P
I am not sure what I imagined or hoped for ๐ Just thought it's worth a shot to ask
umm, I have a lengthy clojure api design(ish) question, are half-pagers ok here or is there a more appropriate channel for this?
i think feedback is always better when you can ask a very concise question with a problem statement that is reduced to the minimal example. whether that takes a half a page is up to the problem. but a question that long probably won't get as much time and responses from others
@mbjarland Maybe #code-reviews is also appropriate, I'm not sure
@mbjarland There's also #architecture which is often more long-form...
Thanks @dpsutton, @borkdude, and @seancorfield - I will try those.
Does anyone know what reporter or other option I would use to get play-by-play test output with kaocha? That is, I want to see the test description and result as it's going, not just a number of failed passed at the end.
@mkeller02 there's a #kaocha channel for that
Thanks @borkdude, FYI I think I rubber ducked this one...what I needed was --reporter kaocha.report/documentation
I'm running into an issue with tools.reader.edn. For reasons I need to be able to pass a LineNumberingPushbackReader for reading. This got me into the following issue:
user=> (require '[clojure.tools.reader.edn :as tre])
nil
user=> (tre/read (clojure.lang.LineNumberingPushbackReader. (java.io.StringReader. "(+)")))
Execution error (IOException) at java.io.PushbackReader/unread (PushbackReader.java:155).
Any ideas why this happens? I can read "(1 2 3 4)"
fine, it's the +
which seems to trigger this
The same issue happens with a "normal" pushbackreader:
user=> (tre/read (java.io.PushbackReader. (java.io.StringReader. "(+)")))
Execution error (IOException) at java.io.PushbackReader/unread (PushbackReader.java:155).
Pushback buffer overflow
I can replicate for +, -, but not for other symbols/numbers, I bet this is a buggy definition or precedence for number parsing
this seems to work,
(tre/read (clojure.tools.reader.reader-types/string-push-back-reader "(+)"))
though I don't know what the difference between the readers is yetyep that works. but that's not what I need. the docstring states: > Reads the first object from an IPushbackReader or a http://java.io.PushbackReader.
(tre/read {:eof nil} (java.io.PushbackReader. (java.io.StringReader. "(+)") 2))
seemingly the buffer size of 1 is too small here, I'm not certain on what dictates the length needed but this works1 character is not enough to determine if + is a number or a symbol ?
Also normal tools.reader
works:
user=> (tr/read (java.io.PushbackReader. (java.io.StringReader. "(+)")))
(+)
Just the tools.reader.edn
barfs on thisI might have a fix:
user=> (tre/read (java.io.PushbackReader. (java.io.StringReader. "(+)")))
(+)
I'll make an issue + patch.
Patch: code + test https://clojure.atlassian.net/browse/TRDR-63
@alexmiller Should I assign it to someone?
no
ok
the repro is good there but I can't tell what the actual cause or the proposed solution is
ok, I'll explain in the issue
https://clojure.atlassian.net/browse/CLJ-1187 is a random example of what I try to do in CLJ tickets
I'll probably do that tomorrow, I'm pretty tired now :)
no worries at all
just a plea from your friendly neighborhood project maintainer
@alexmiller Now added explanation