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.

Alex Miller (Clojure team)01:02:51

They’ve been adding guards in the recent Linux builds

jaihindhreddy-duplicate06:02:32

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

jaihindhreddy-duplicate06:02:27

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

Alex Miller (Clojure team)06:02:54

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

👍 5
Alex Miller (Clojure team)06:02:13

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

Alex Miller (Clojure team)06:02:02

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

👍 5
Ian Fernandez13: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

Ian Fernandez13:02:21

But sometimes I have values that are lists of maps too

Ian Fernandez13:02:46

how can I apply this to nested maps?

Ian Fernandez13:02:10

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

Ian Fernandez13: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

Ian Fernandez13:02:21

what about specter?

Ian Fernandez13:02:14

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

Ian Fernandez13: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

Ian Terrell16: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?

drone17:02:14

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

👍 5
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

👍 5
drone17: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?

willahhh20: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.

👌 5
willahhh20: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 😛

simple_smile 5
Lennart Buit20:02:57

typing before thinking sometimes gets the better of me

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

Ram20: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

Ram20:02:00

Thanks @john #leiningen was what I was looking for

👍 5
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)

Alex Miller (Clojure team)22: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.

👍 5
Alex Miller (Clojure team)22:02:28

that is definitely a known issue