This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-06
Channels
- # babashka (31)
- # beginners (108)
- # calva (6)
- # clj-kondo (62)
- # cljsrn (5)
- # clojure (29)
- # clojure-australia (2)
- # clojure-europe (17)
- # clojure-nl (2)
- # clojure-spec (5)
- # clojure-uk (7)
- # clojurescript (25)
- # code-reviews (1)
- # datomic (13)
- # deps-new (7)
- # editors (1)
- # emacs (31)
- # figwheel-main (3)
- # garden (4)
- # graalvm (18)
- # helix (10)
- # improve-getting-started (12)
- # jobs (3)
- # lsp (20)
- # malli (12)
- # off-topic (7)
- # polylith (30)
- # re-frame (10)
- # remote-jobs (2)
- # shadow-cljs (18)
- # spacemacs (5)
- # sql (11)
- # tools-deps (10)
- # vim (9)
- # xtdb (1)
Is there a way to check that a string is valid as a keyword? Currently I can do (keyword "a,b")
which creates a keyword that cannot be represented as literal, i.e. :a,b
is not accepted (rightly so). Before I call keyword
on a string, how can I check / ensure it only contains valid characters? 🙏
https://clojure.org/reference/data_structures#Keywords says little...
I guess I could write a manual check for the rules described under https://clojure.org/reference/reader#_symbols and Literals / Keywords little more down?
are you serializing data to edn?
No, generating Datomic attributes from customer-defined "custom fields" with a string name
static Pattern symbolPat = Pattern.compile("[:]?([\\D&&[^/]].*/)?(/|[\\D&&[^/]][^/]*)");
I have tried it, but
(def p (java.util.regex.Pattern/compile "[:]?([\\D&&[^/]].*/)?(/|[\\D&&[^/]][^/]*)"))
(-> p (.matcher "abc,b") .matches)
; => true
x I expect falsetools.reader is more strict about keywords (among other things), you can either use it or inspect its source for inspiration
Ah, it reads tokens. And commas are treated as whitespace that, of course, separates tokens. Also a few other chars are important, but you wanna check the implementation for that yourself - it's not that easy to describe succinctly.
Thank you. For the time being I will be very strict and follow what https://clojure.org/reference/reader#_symbols describes and check for (re-matches #"[\w*+!-'?<>=]+" name)
you could always round trip it and see if it changes ...
(let [x (keyword "a,b")]
(= (clojure.edn/read-string (str x)) x))
> Keywords - Keywords are like symbols, except: > They cannot contain '.' in the name part, or name classes. > Like symbols, they can contain a namespace, :person/name, which may contain '.'s.
Huh! Found this: https://ask.clojure.org/index.php/2808/specifically-allow-inside-keywords And yeah, I've been seeing them for years, both in CLJ and in CLJS. Would never have guessed the docs explicitly disallow it for some reason.
user=> :
:
at least one widely used clojure lib uses keyword literals like this, I wouldn't expect a change to the clojure reader that prevents it workingOh wow. :) I was thinking about plain keywords like :user.id
(which a user of HoneySQL, at least v1, might use) or :div.login-form
(when using Hiccup).
Is there some blocking function for pulling values from async channel into a collection that’s supplied with the library? I haven’t spotted one. I can <!!
in a loop, I know, but I am wonder if there’s one already.
Not sure what you mean by "a collection that’s supplied with the library". But maybe a/into
?
thanks
but that isn’t what I was looking for, it returns a channel
Given the following code
(defmacro reg-fn [k f] ...)
(defn some-fn [] ...)
(reg-fn :my-fn some-fn)
Is there a way to get to the name of f
passed into the macro (`some-fn` in this case). I want to check if the name conforms to a certain convention, and throw an exception if it does not.
I’d also be happy with some-namespace$some-fn
or even better the metadata of some-fn
Thanks