This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-01
Channels
- # announcements (7)
- # babashka (10)
- # beginners (60)
- # clerk (4)
- # clojure (19)
- # clojure-conj (5)
- # clojure-europe (48)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-uk (2)
- # clojurescript (12)
- # conjure (2)
- # core-async (24)
- # cursive (3)
- # datalevin (18)
- # events (1)
- # figwheel-main (5)
- # fulcro (22)
- # honeysql (29)
- # hyperfiddle (60)
- # jobs (3)
- # leiningen (18)
- # lsp (47)
- # meander (21)
- # missionary (6)
- # off-topic (35)
- # reagent (14)
- # remote-jobs (1)
- # ring (1)
- # shadow-cljs (32)
- # sql (10)
- # transit (12)
Transit seems to interpret "~"
as a tagged string with no tag and no string value. Is this the proper interpretation?
(#C031CBEUTGS is a thing btw) I'm a bit rusty, but I don't think that is a valid piece of transit
Say I’ve got a map of keys and sequential values like:
{:k [k1 k2 k3] :l [l1 l2]}
How would I go about creating the permutations of all the keys and values in separate maps? e.g something like:
[{:k k1 :l l1} {:k k2 :l :l1} … {:k k3 :l l2}]
(let [m {:k '[k1 k2 k3] :l '[l1 l2]}]
(for [k (:k m)
l (:l m)]
{:k k :l l}))
({:k k1, :l l1}
{:k k1, :l l2}
{:k k2, :l l1}
{:k k2, :l l2}
{:k k3, :l l1}
{:k k3, :l l2})
I perhaps should have specified that I would like a solution that doesn’t depend on manually enumerating the keys - one that works for any arbitrary map of this shape
(defn perm [m]
(let [ks (keys m)
vs (vals m)]
(mapv #(zipmap ks %)
(apply combi/cartesian-product vs))))
(perm '{:k [k1 k2 k3] :l [l1 l2]})
=> [{:k k1, :l l1} {:k k1, :l l2} {:k k2, :l l1} {:k k2, :l l2} {:k k3, :l l1} {:k k3, :l l2}]
A question about load-file
. The docstring of ns
states
> Sets ns to the namespace named by name (unevaluated), creating it
> if needed.
and of course, if you evaluate an ns
form it sets your repl. But load-file
states
> Sequentially read and evaluate the set of forms contained in the file.
So that gives me the expectation that (load-file "some_file.clj")
would evaluate any ns
form in some_file.clj
if present, and thereby setting the namespace to the ns defined by that form. But this does not seem to be the case. Should a docstring be updated to reflect this?
Are you saying you'd expect it to change *ns*
in the calling code?
that’s what the docstrings together imply right? load-file
evaluates forms, ns
form sets the current namespace. So if you load-file
on a file that has an ns
form my expectation is that it does all of the side effects of evaluating those forms
it looks like Compiler.load
does Var.pushThreadBindings
and then pops at the end which is presumably what inhibits the changing of the ns
Yeah, I would not expect *ns*
changes to bleed out of loading (and eval'ing) a file...
So I guess clarification of the push/pop in load-file
's docstring would help.
(i’ve also exclusively used require
with :reload
and have to use load-file
to work around a bug in cljs. And my first worry after reading the docstring is that it would change the current ns. then I was confused as to why it didn’t
load-file doesn't change the current ns, the ns binding is restored (popped) afterwards