This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-15
Channels
- # adventofcode (13)
- # aleph (5)
- # announcements (8)
- # beginners (87)
- # calva (9)
- # cider (102)
- # cljs-dev (71)
- # cljsrn (2)
- # clojure (198)
- # clojure-dev (28)
- # clojure-europe (3)
- # clojure-italy (27)
- # clojure-nl (3)
- # clojure-spec (1)
- # clojure-uk (43)
- # clojurescript (121)
- # component (11)
- # cursive (20)
- # data-science (13)
- # datascript (2)
- # datomic (102)
- # dirac (4)
- # duct (5)
- # emacs (14)
- # figwheel-main (7)
- # fulcro (37)
- # hoplon (11)
- # jackdaw (3)
- # jobs (2)
- # leiningen (16)
- # nrepl (2)
- # off-topic (51)
- # pathom (34)
- # pedestal (12)
- # perun (10)
- # portkey (1)
- # re-frame (6)
- # reitit (1)
- # shadow-cljs (21)
- # spacemacs (8)
- # tools-deps (2)
- # vim (2)
Scratch that "both ways" thing for my Linux results -- no user.clj only took about 15 seconds. (I forgot to remove user.clj the first time I tried requiring from clojure command line)
Interesting, so perhaps this is a bug in later linux JDK releases?
Perhaps. I don't have much of a clue what is going on there.
They’ve been adding guards in the recent Linux builds
java 8 u201
https://www.oracle.com/technetwork/java/javase/8u201-relnotes-5209271.html
Just like 'foo
can be written in EDN like (quote foo)
, can ` and ~ be represented in EDN?
~
seems to be clojure.core/unquote
. Can't find a clojure.core/syntax-quote
though.
they are instructions to the Clojure reader itself (which the edn reader does not understand)
unquote
(and unquote-splicing
) are just unbound symbols defined in clojure.core
user=> ``(foo ~a)
(clojure.core/seq (clojure.core/concat (clojure.core/list (quote user/foo)) (clojure.core/list user/a)))
(defn camelCase-map [item]
(reduce-kv
(fn [m k v]
(assoc m (csk/->camelCase k)
v)) {} item))
I have this to convert keys from a map to camelCaseBut sometimes I have values that are lists of maps too
how can I apply this to nested maps?
{:a-b 1 :a-c ({:a_d 3 :a_b 4} {:d_a 1 :c-a 3})}
giving me:
{:aB 1 :aC ({:aD 3 :aB 4} {:dA 1 :cA 3})}
thanks 😃
what about specter?
@d.ian.b I’m using this lib for it: https://github.com/qerub/camel-snake-kebab
i'm using this one but I need for nested maps
to convert keyword in nested maps
Snippet from our codebase:
(defn transform-keys
"Given a map m and a function a-fn1, will apply that function to all
keys in the map, recursively (unless non-recursive? is true). Returns
modified map."
([a-fn1 m]
(transform-keys a-fn1 m true))
([a-fn1 m non-recursive?]
(let [rf (fn [tm [k v]] (assoc! tm (a-fn1 k) v))]
;; only apply to maps
(if non-recursive?
(treduce rf {} m)
(postwalk (fn [x] (if (map? x) (treduce rf {} x) x)) m)))))
(defn snake_casify
([m]
(snake_casify m false))
([m non-recursive?]
(let [kf (fn [k]
(if (namespace k)
(keyword (->snake_case (namespace k))
(->snake_case (name k)))
(->snake_case_keyword k)))]
(transform-keys kf m non-recursive?))))
Can anyone offer a pointer on how to create a command line REPL for a Clojurescript project that can access installed node_modules?
All in the same directory I have a src
folder, a deps.edn
that includes src
in :paths
, package.json
and node_modules
with installed modules.
I can boot a REPL with clj -m cljs.main -re node
, and it can find my code. But it can't find the installed Node modules.
ClojureScript 1.10.439
cljs.user=> (require '[db.etl.staging])
module.js:545
throw err;
^
Error: Cannot find module 'aws-sdk'
at Function.Module._resolveFilename (module.
...
Any pointers?Any idea how to update/manipulate primitive with meta, without losing its meta. Eg. => (def a (with-meta [1 2 3] {:my "meta"})) => (def b (remove #{3} a)) => ;; now b losing its meta.
that makes sense right, because you are producing a new value
haha, teamwork 😛
well, you can use meta
to get the metadata, so if you would change your b
def to ^
@ian451 I’ve heard good things about shadow-cljs, though haven’t had a chance to use it yet.
It was created, so I understand, to make npm interaction as simple as possible (among other things, I’m sure)
I’m not sure how to do it with just a deps file; maybe the clojure script channel knows?
Thanks!
Hellow Clojurians, is there a way to represent namespaced keyword ? Like :module-a/list/current-display
namespaced keywords are a native concept to clojure. however they don't allow multiple slashes
that's techically multi segmented and not meaningfully nested, but yes
Yes. So for the above, you'd have (ns module-a.list ...)
which would be src/module_a/list.clj
and :module-a.list/current-display
would match that namespace.
But namespaced keywords don't need an actual code namespace behind them, so :this.is.my.fake.namespace/my-key
would be just fine.
(if there is a ns backing them, you can require/as them tho)
(mighty useful)
Aye... And calling ::current-display
will expand into :my.current.name-space/current-display
, as a shorthand
You don't "import" keywords tho', but (require [module-a.list :as mlist])
and then ::mlist/current-display
saves typing 🙂
typing before thinking sometimes gets the better of me
Aye, @seancorfield's example explains @lennart.buit's reference to :as
Also, you can create aliases for namespaces that have no code: (alias 'mstuff (create-ns 'module-a.mstuff))
as I recall.
From our codebase
(alias 'm (create-ns 'ws.domain.member))
(alias 'mu (create-ns 'ws.domain.member.update))
(alias 'mv (create-ns 'ws.domain.member.validation))
so we can do ::m/email
, for example.oh thats pretty cool!
(now, it just happens that we actually do have code namespaces that match those, but this allows us to refer to keywords in them without actually requiring the namespaces -- because in some parts of our code we don't need to load that stuff, just use the keywords)
Where do you have these aliases defined then, if I may ask
@lennart.buit Those aliases are in any file where we need only the keywords, not the code behind them.
right, thanks!
that could lead to weird results if you have tooling that uses eg. all-ns
in an automated way
hypothetically - I don't know of anything it actually breaks
@noisesmith that's some good out-of-the-box, systems thinking there. nice.
Though it feels like all-ns
shouldn't be tied too much to app logic. Feels like a repl tool.
right - or a refactor tool
it wouldn't be out of the question to do something like (->> (all-ns) (filter contains-multimethod-impl?) (run! load-for-multi))
as a DI approach to multimethod extension
right - that would be a repl thing
how can I clean all built dependencies for a deps.edn clj project?
getting weird dependencies errors
I guess my question is, how can I get a clean state of dependencies loaded via classpath (using cursive)
there are several caches - /m2/repository caches jar files, /.cpcache caches classpaths, ~/.gitlibs caches git deps
@pvillegas12 removing the .cpcache
folder in your project should be sufficient -- we've found that changes to transitive dependencies via :local/root
don't seem to be detected so we've had to delete .cpache
in each sub-project as part of our build pipeline.
that is definitely a known issue