This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-25
Channels
- # announcements (5)
- # babashka (23)
- # beginners (70)
- # cider (24)
- # clj-kondo (14)
- # cljsrn (2)
- # clojars (6)
- # clojure (195)
- # clojure-australia (1)
- # clojure-dev (2)
- # clojure-europe (27)
- # clojure-france (1)
- # clojure-nl (4)
- # clojure-norway (2)
- # clojure-spec (2)
- # clojure-uk (12)
- # clojurescript (3)
- # clojurewerkz (1)
- # core-async (21)
- # cursive (9)
- # datomic (37)
- # duct (3)
- # emacs (16)
- # events (4)
- # fulcro (34)
- # graalvm (12)
- # javascript (3)
- # jobs (4)
- # malli (1)
- # meander (3)
- # nrepl (1)
- # off-topic (27)
- # pathom (16)
- # re-frame (17)
- # reagent (19)
- # rewrite-clj (18)
- # sci (47)
- # shadow-cljs (179)
- # spacemacs (18)
- # sql (52)
- # tools-deps (80)
- # vim (27)
- # vrac (1)
- # xtdb (9)
Hi i'm wondering about url encoding
I use cljs to get the location of the window href location but it has nonenglish characters... it seems to lose its ascii'ness... can I recover this in cljs land
I think this is what you want https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI
setting the URL automatically encodes it
thx resolved in cljs
If I have a map of strings. {:a "aaa" :b "" :c "ccc"}
what is the best way to make a concatenated string of these values including a prefix only for those keys having a non-empty string. So in this case the resulting string should be "Something: aaa. Something: ccc"
(clojure.string/join ". " (map #(str "Something: " (val %1)) (remove (comp clojure.string/blank? second) foo)))
user=> foo
{:a "aaa", :b "", :c "ccc"}
user=> (clojure.string/join ", " (map #(str "Something: " (val %1)) (remove (comp clojure.string/blank? second) foo)))
"Something: aaa, Something: ccc"
Thread-last seems to be suitable, otherwise copying @dharrigan's code:
(def foo {:a "aaa" :b "" :c "ccc"})
(->> (vals foo)
(remove clojure.string/blank?)
(map #(str "Something: " %))
(clojure.string/join ", "))
;; => "Something: aaa, Something: ccc"
yes, I debated thread too, but I though that comp would be a bit easier to grok initially, but that said, thread macro is pretty straight forward too
Are watchers intended to be used as part of regular programming flow? Or are they mainly for observability?
iirc most of the time you want core.async instead
Hey, is using a multimethod a good way to model the following situation: I get either a scalar or a collection of the scalar, when a collection is transmitted I just call the "base" method with map
or reduce
. Or is it better to write my own top level dispatch function?
the best practice is to never have a function that takes a collection or non-collection in those cases where it's mandatory (some api you don't control sometimes gives you an item outside a collection, sometimes gives you a collection) use the following at the point you acquire the data:
(defn fix-api-result [x]
(if (coll? x)
x
[x]))
other solutions (including multimethods) end up profilorating the implementation detail of a bad API design into the rest of your codebasedepending on how you get the data, coll?
might be the wrong pred (eg. you might want seqable?
and then call seq
if true)
How do you configure pprint with cider? What I would like to achieve is that when I press C-c C-e
the evaluation result gets pprint. Is that possible? I tried (set! nrepl.middleware.print/*print-fn* clojure.pprint/pprint)
but this only works inside the repl ...
FYI there is also a #cider channel here, which is often good for such questions. No problem asking here -- just the expertise on Cider is likely more concentrated there.
Hey, couple questions on macros: 1. Is it accurate to say that defmacro is equivalent to defn except that the former is executed at compile time and the latter at runtime? 2. How often do you guys end up writing your own macros in "real-world" code?
I guess another way defmacro is different than defn is that its arguments aren't evaluated before invocation. Are there other differences?
no. 1 is not accurate. a common counterexample is that you can call functions defined with defn
within a macro
Not a compile time but during Read phase in repl
or you could say, it is compile time for the code being macroexpanded, but runtime for the macro and functions that the macro calls
it's not a completely useless distinction, but there's less of a distinction between runtime and compile time in clojure
because the macro (meta) language and the language are the same it is easy to tie yourself into a knot
macros are not run during the read phase
They are
> (read-string "(defn a [] 1)")
(defn a [] 1)
Read string is for reading string as a list of symbols
the reader reads things and produces data structures, the datastructures are evaluated (which in clojure's case means compilation to bytecode and execution of the bytecode), and the result is printed
and during the compilation of a given form, the results of previous evaluations (functions, definitions, etc) are available to macros
results aren't printed during evaluation. the printing is a separate step that may or may not happen
but, I concur with @U0NCTKEV8, macros are run at compile time. during compilation, functions created using defn
may also be run
Are reader macros different from regular macros? Are they compiled at read time or also compile time?
Reader macros are really just shorthand in the reader itself and they are very limited -- see https://clojure.org/guides/faq#reader_macros
The specific reader macros themselves are discussed here https://clojure.org/guides/weird_characters
but they do happen at read time:
> (pr-str (read-string "@foo"))
"(clojure.core/deref foo)"
They're not really "compiled" though. They are almost the very definition of "syntactic sugar" in terms of the source transformation.
And I don't think anyone answered your original second question @U015RJM9ARG "How often do you guys end up writing your own macros in "real-world" code?" -- the answer is "rarely".
Here's some raw stats from our codebase at work
Clojure build/config 56 files 1006 total loc
Clojure source 318 files 77927 total loc,
3304 fns, 742 of which are private,
469 vars, 27 macros, 79 atoms,
631 specs, 33 function specs.
Clojure tests 349 files 22445 total loc,
4 specs, 1 function specs.
@U015RJM9ARG Oh no, not by far. But it is big enough that it brings some interesting problems in terms of code organization (and code duplication that is hard to find).
Hi, I get a strange error that I think has to do with class path... ?
Syntax error (UnsupportedClassVersionError) compiling at (datahike/impl/entity.cljc:1:1).
datahike/java/IEntity has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I'm not an expert but seems like a java env/path error? Java Runtime only recognizes class file versions up to 52.0
This part is saying you need at least java 8
it really depends on where you got the jar from - for local dev, configure it to compile and be compatible with your VM for using libs, either update to a newer jvm, or find an alternative that works on your old VM
(I don't think most of us are using IDEs)
:thinking_face: I thought that intellij cursive is quite popular but thats just a guess 🙈😇
Thanks I upgraded the server box to java 14 and it is all better now
I'm using cruxdb, and I'm trying to figure out a good way to return documents that have other documents embedded inside them. The document itself stores an id, but I ned the full data to send to my client.