Fork me on GitHub
#beginners
<
2019-02-15
>
andy.fingerhut00:02:05

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)

rschmukler00:02:32

Interesting, so perhaps this is a bug in later linux JDK releases?

andy.fingerhut00:02:54

Perhaps. I don't have much of a clue what is going on there.

alexmiller01:02:51

They’ve been adding guards in the recent Linux builds

jaihindh.reddy06:02:32

Just like 'foo can be written in EDN like (quote foo), can ` and ~ be represented in EDN?

jaihindh.reddy06:02:27

~ seems to be clojure.core/unquote. Can't find a clojure.core/syntax-quote though.

alexmiller06:02:54

they are instructions to the Clojure reader itself (which the edn reader does not understand)

alexmiller06:02:13

unquote (and unquote-splicing) are just unbound symbols defined in clojure.core

alexmiller06:02:02

user=> ``(foo ~a)
(clojure.core/seq (clojure.core/concat (clojure.core/list (quote user/foo)) (clojure.core/list user/a)))

d.ian.b13:02:03

(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 camelCase

d.ian.b13:02:21

But sometimes I have values that are lists of maps too

d.ian.b13:02:46

how can I apply this to nested maps?

d.ian.b13:02:10

{:a-b 1 :a-c ({:a_d 3 :a_b 4} {:d_a 1 :c-a 3})}

d.ian.b13:02:50

giving me:

{:aB 1 :aC ({:aD 3 :aB 4} {:dA 1 :cA 3})}

avfonarev13:02:10

@d.ian.b You might take a look at clojure.walk

d.ian.b13:02:28

thanks 😃

d.ian.b13:02:21

what about specter?

d.ian.b13:02:14

i'm using this one but I need for nested maps

d.ian.b13:02:25

to convert keyword in nested maps

borkdude13:02:03

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?))))

borkdude13:02:22

but Specter may work too 😉

borkdude13:02:31

this is basically postwalk from clojure.walk doing the work

ian45116:02:38

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?

codxse17:02:07

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.

lennart.buit17:02:34

that makes sense right, because you are producing a new value

lilactown17:02:50

so you'll need some way of copying the meta to the new value

lennart.buit17:02:10

haha, teamwork 😛

codxse17:02:35

So, how do I copy the meta?

mrevelle17:02:14

(def b (with-meta (remove #{3} a) (meta a)))

lennart.buit17:02:24

well, you can use meta to get the metadata, so if you would change your b def to ^

lennart.buit17:02:31

drone beat me to it

mrevelle17:02:47

not sure what you’re trying to do though, may not be best use of metadata

codxse17:02:06

thanks guys!, I am just tooling around

futuro19:02:46

@ian451 I’ve heard good things about shadow-cljs, though haven’t had a chance to use it yet.

futuro19:02:12

It was created, so I understand, to make npm interaction as simple as possible (among other things, I’m sure)

futuro19:02:56

I’m not sure how to do it with just a deps file; maybe the clojure script channel knows?

wravel20:02:32

Hellow Clojurians, is there a way to represent namespaced keyword ? Like :module-a/list/current-display

dpsutton20:02:30

namespaced keywords are a native concept to clojure. however they don't allow multiple slashes

john20:02:21

Wouldn't it be :module-a.list/current-display?

john20:02:45

nested namespaces should be represented by a period, right?

noisesmith20:02:29

that's techically multi segmented and not meaningfully nested, but yes

seancorfield20:02:46

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.

wravel20:02:13

Oh ok thank you

seancorfield20:02:22

But namespaced keywords don't need an actual code namespace behind them, so :this.is.my.fake.namespace/my-key would be just fine.

lennart.buit20:02:47

(if there is a ns backing them, you can require/as them tho)

lennart.buit20:02:50

(mighty useful)

john20:02:11

Aye... And calling ::current-display will expand into :my.current.name-space/current-display, as a shorthand

dpsutton20:02:32

and commonly {:user/name "bob" :organization/name "clojurians"} etc.

seancorfield20:02:47

You don't "import" keywords tho', but (require [module-a.list :as mlist]) and then ::mlist/current-display saves typing 🙂

lennart.buit20:02:06

right, I ninja’edited my message 😛

lennart.buit20:02:57

typing before thinking sometimes gets the better of me

wravel20:02:55

I see 🙂

john20:02:30

Aye, @seancorfield's example explains @lennart.buit's reference to :as

seancorfield20:02:33

Also, you can create aliases for namespaces that have no code: (alias 'mstuff (create-ns 'module-a.mstuff)) as I recall.

seancorfield20:02:17

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.

lennart.buit20:02:54

oh thats pretty cool!

seancorfield20:02:38

(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)

lennart.buit20:02:53

Where do you have these aliases defined then, if I may ask

seancorfield21:02:44

@lennart.buit Those aliases are in any file where we need only the keywords, not the code behind them.

lennart.buit21:02:47

right, thanks!

noisesmith20:02:25

that could lead to weird results if you have tooling that uses eg. all-ns in an automated way

noisesmith20:02:01

hypothetically - I don't know of anything it actually breaks

john20:02:25

@noisesmith that's some good out-of-the-box, systems thinking there. nice.

john20:02:55

Though it feels like all-ns shouldn't be tied too much to app logic. Feels like a repl tool.

noisesmith20:02:03

right - or a refactor tool

john20:02:15

ns's aren't immutable things in clojure, after all... yea, testing maybe too

noisesmith20:02:23

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

john20:02:14

for repling

noisesmith20:02:30

right - that would be a repl thing

tramsey20:02:54

Is this a good channel for questions/issues with Leiningen?

john20:02:27

If you can't get an answer in #leiningen, probably @tramsey

tramsey20:02:00

Thanks @john #leiningen was what I was looking for

pvillegas1221:02:45

how can I clean all built dependencies for a deps.edn clj project?

pvillegas1221:02:05

getting weird dependencies errors

hiredman21:02:34

deps.edn doesn't build dependencies

pvillegas1221:02:01

I guess my question is, how can I get a clean state of dependencies loaded via classpath (using cursive)

alexmiller22:02:59

there are several caches - /m2/repository caches jar files, /.cpcache caches classpaths, ~/.gitlibs caches git deps

seancorfield22:02:58

@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.

alexmiller22:02:28

that is definitely a known issue