This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-09
Channels
- # adventofcode (1)
- # aleph (2)
- # beginners (28)
- # boot (26)
- # boot-dev (8)
- # cider (10)
- # clara (10)
- # cljs-dev (130)
- # cljs-experience (1)
- # cljsrn (12)
- # clojure (118)
- # clojure-austin (40)
- # clojure-boston (1)
- # clojure-chicago (1)
- # clojure-dusseldorf (1)
- # clojure-estonia (11)
- # clojure-france (1)
- # clojure-greece (3)
- # clojure-italy (19)
- # clojure-nl (1)
- # clojure-russia (1)
- # clojure-spec (19)
- # clojure-uk (34)
- # clojurescript (62)
- # core-logic (7)
- # cursive (11)
- # datomic (35)
- # emacs (15)
- # fulcro (264)
- # jobs (4)
- # leiningen (5)
- # midje (4)
- # off-topic (74)
- # onyx (27)
- # planck (14)
- # protorepl (4)
- # re-frame (37)
- # reagent (62)
- # rum (2)
- # shadow-cljs (171)
- # slack-help (5)
- # spacemacs (6)
- # specter (9)
is there a clojure builtin which does: (fand f g h i) -> #(and (apply f %&) (apply g %&) (apply h %&) (apply i %&)) ?
every-pred
is pretty close
implementation so far:
(def fand0 (fn [lst]
(let [args (gensym "args")]
`(fn [& ~args]
~`(and ~@(for [f lst]
`(apply ~f ~args)))))))
(fand0 '[a b c])
(defmacro fand [& lst] (fand0 lst))
my project X has a dependency on a project Y which depends on Loom, but when I require a namespace from Y that uses Loom I get
java.lang.RuntimeException: No such var: pm/priority-map-keyfn
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: No such var: pm/priority-map-keyfn, compiling:(loom/alg.cljc:570:33)
...however, if I include Loom in X's dependencies, it works...why is that ?
if you use a namespace directly, you have a direct dependency on a project. this is enforced by maven's design.
ok how does that explain the reason for the error ?
(just to be clear, the error happens when requiring a namespace from Y in a namespace of X, when X doesn't itself include Loom as a dependency (Loom is a dependency of Y))
here is the XY problem: I have a *.cljc file; I want t read it in and do some static analysis on it
unfortunately, (read-string {:read-cond :allow} ...) is basically replacing all my #?(...) with nil
(let [ans (binding [r/*read-eval* false]
(r/read-string {:read-cond :preserve}
(str "#?(:clj 2)" )))]
[ans (type ans)])
(comment
[#?(:clj 2) clojure.lang.ReaderConditional])
I can work with this@qqq Not sure what your goal is but maybe also check out: https://github.com/aengelberg/cljsee
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/ReaderConditional.java <-- alright, so I see a valAt
but how do I get the list of possibl ekeys
for all intent purposes, I can imagine it's a
{:form (actual code after the #?)
:splicing? (whether it's #? or #?@) ?
except it's a java object and not a clojure map(def cljc-read-string (fn [fname] (binding [r/*read-eval* false]
(let [ans (r/read-string {:read-cond :preserve}
(str "(\n" (slurp fname ) "\n)"))]
ans))))
(for [x (cljc-read-string "src/a/abcd.cljc")]
(meta x))
(comment
(nil nil nil nil))
any advice on how do pull the meta data ?actually, can you just point me at docs? I'm somehow not finding them, and taking up too much of your time
@qqq:
[clojure.tools.reader :as r]
[clojure.tools.reader.reader-types :as reader-types]
(defn indexed-read [data]
(-> data
reader-types/indexing-push-back-reader
r/read))
@robert-stuttaford: worked brilliantly, thanks!
https://github.com/clojure/tools.reader/search?utf8=%E2%9C%93&q=comment&type= does NOT support preserving comments does it? (for part the app, I need to do *.cljc -> hyperlinked svg files for displaying the code, so I have a slight preference of keeping ";; ... " style comments if possible)
(def model (-> "model/data-model.edn" io/resource slurp read-string))
=> #'user/model
(s/conform ::ddd/model model)
=> :clojure.spec.alpha/invalid
(s/explain ::ddd/model model)
Success!
=> nil
ask in #clojure-spec, @stijn 🙂
(def idx-read-one (fn [rdr] (try (r/read {:read-cond :preserve} rdr)
(catch Exception e nil))))
(def idx-read-all (fn [fname]
(binding [r/*read-eval* false]
(let [rdr (-> fname io/file io/reader java.io.PushbackReader.
reader-types/indexing-push-back-reader)]
(loop [forms []]
(let [form (idx-read-one rdr)]
(if form
(recur (conj forms form))
forms)))))))
I find the last 5 lines inelegant. There should be some way to say "tun this until it's nil"hmm, (for [form (idx-read-one rdr) :while (not (nil? form))] form)
haven’t tried that, but maybe that would work?
@manutter51: yeah, the take-while and for solutions should do the same
I think it'd have to be (for [form (repeatedly #(idx-read-one rdr)) :while (some? form)] form)
ah, right, that’s what I meant 😉
Looks good to me
Smb know how add step before
lein uberjar
like build or execute some bash script?@fantomofdoom :prep-tasks
https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L262 - this shows top level prep-tasks, but you can also use that key inside the :uberjar
profile
does anyone know if there's a good place to learn about the specific design decisions and philosophy that went into Clojure?
my brother is clojure dev and he's fascinated me with little nuggets of wisdom like "a sequence is anything that implements first, rest, and cons..." and I'm like, "whoa". And other things like "never program to a datatype, program to an abstraction". and I'm like "whoa" again.
Do those sorts of nuggets come from Rich's talks?
yes, he talks about those things
“Are we there yet?” is a talk that holds up well and is perhaps the most accessible
Design, Composition, Performance talks about his approach to design itself. i think it's a great counterpart to Simple Made Easy @goomba
oh beautiful
the talks are definitely the most accessible. if you’re willing to dig a little bit more, the jira for clojure has had lots of interesting discussions, https://dev.clojure.org/jira/secure/IssueNavigator.jspa
slides and transcript for Design, Composition, Performance: https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/DesignCompositionPerformance.md
Are ^:const definitions replaced before macro expansion?
Also, is there a difference between clj and cljs?
there are many large and small differences between clj and cljs, including how const works
Alright, that may be my issue then. I have a cljc file, and I'm trying to use a ^:const inside a macro usage. I'm assuming the macro is trying to modify the contents of the const. Still waiting on a response in #rum on that.
So is my best bet to create a macro to return that static data?
That's interesting. What's the reasoning for that?
I have yet to talk to anyone who wanted to use it that understood what it does completely
by that I mean the way const works has knock on effects that interact weirdly with other things like case (which if I recall is one one of the differences between clojure and clojurescript)
as far as I know there is little to no documentation about what it does, the only way to know is to read the compiler
but the name is so unassuming that anyone reading it will assume they know what it does
That makes sense. I've only just run across it, and you're right, I did immediately assume it was what I expected. (constants in haxe)
if I recall, I think some other advice I have seen regarding const is: only use it for primitive numeric literals
Makes sense, thanks!
So the only way to do a true multi-place replacement would be a macro?
Inline styles in rum. Rum needs to convert the style edn, but it doesn't seem to unless it's actually in the macro (not just referencing a variable).
So I have a "class" which is just some inline styles and can be used in multiple places.
Macros are expanded in order, no?
From bottom to top?
Oh, ok.
No that you say that, it makes sense.
So a macro could return another macro.
Now that*
That spells it out pretty nicely. But yeah, pretty niche use case for how often I come across it.
if anything the example there is kind of the reverse case of what most people assume ^:const means
So it's only for definitions which aren't static but require a transform of other static data?
In any case, it doesn't do it before macro expansion.
ok, right, it does do the thing you expect(sort of) but that example is taking advantage of clojure's top level form as a compilation unit to make it sort of do the other thing
the line defining pi is compiled and run more or less normally as a def, the value part is executed to get the value of the var, then whenever the var is reference elsewhere, instead of compiling as a var deref, it is compiled as a quoted form of whatever value the var has at that point
Interesting
I just did a quick test of a macroexpand with a ^:const, and it does indeed not expand it.
I encountered a bug related to ^:const not long ago https://github.com/danlentz/clj-uuid/issues/37