Fork me on GitHub
#beginners
<
2018-04-09
>
jrbrodie7701:04:11

I’m using figwheel with cursive. Does anyone know how to make doc, pprint, dir, to etc. follow me around from namespace to namespace? Or do I have to require it everywhere separately?

zlrth02:04:35

I have a process (datomic fwiw) that's sending over a lot of logging messages to cider-nrepl. I asked on #datomic how to lower the logging level in the logback.xml file[0]. But noisy processes logging-too-much is a problem I encounter often enough that I'd like a solution that works on the cider-nrepl side. This would be ideal: https://github.com/clojure-emacs/cider/pull/1907 But I recognize that it's not good practice. Question: How do you deal with noisy processes? [0] The specific problem is: "datomic start" command isn't finding my logback.xml file.

zlrth02:04:55

That PR wasn't merged fwiw.

aengelberg03:04:13

I have the same problem all the time (with cider) and haven't found a solution yet 😞

dpsutton04:04:23

In CIDER, hit comma at a repl promt and select require repl utils

aengelberg03:04:43

maybe the folks in #cider would know better

🌞 4
xlevus03:04:32

is (binding) thread safe?

aengelberg03:04:31

what happens in binding stays in binding

xlevus03:04:15

so what's the difference between binding and with-binding? The docs suggest with-bindings is more thread-safe (if only because it specifically mentions threadlocals)

noisesmith04:04:49

binding is also thread-safe

noisesmith04:04:49

both call push-thread-bindings

noisesmith04:04:41

@xlevus: the difference is that with-thread-bindings wants a function to apply, and a collection of args, while binding takes an arbitrary body of code

noisesmith04:04:49

otherwise they do the same thing

Kari Marttila09:04:19

I just can't figure out how to change the server port in Figwheel. If I change the server port to anything else than the default 3449 (using :server-port 3445) then in the browser (Chrome) I get an error saying "WebSocket connection to '<ws://localhost:3449/figwheel-ws/app>' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED". I have tried to give in the :websocket-url parameter the needed url (:websocket-url "<ws://localhost:3445/figwheel-ws/app>" but Chrome still gives the same error message (complaining that it tries to connect port 3449).

fmn11:04:34

@kari.marttila can we see your figwheel code?

Kari Marttila11:04:07

@funyako.funyao156: here is my figwheel configuration: This works: :figwheel {:http-server-root "." :nrepl-port 7002 :nrepl-middleware ["cemerick.piggieback/wrap-cljs-repl"] :css-dirs ["public/css"]} :cljsbuild {:builds {:app {:source-paths ["src" "env/dev/cljs"] :compiler ... :figwheel {:on-jsload "simplefrontend.core/mount-root" } } ... => Browser works just fine in http://localhost:3449 This ain't working: :figwheel {:http-server-root "." :server-port 3445 ;; default is 3449 :nrepl-port 7002 :nrepl-middleware ["cemerick.piggieback/wrap-cljs-repl"] :css-dirs ["public/css"]} :cljsbuild {:builds {:app {:source-paths ["src" "env/dev/cljs"] :compiler ... :figwheel {:on-jsload "simplefrontend.core/mount-root" :websocket-url "<ws://localhost:3445/figwheel-ws/app>" } } ... => In http://localhost:3445 browser complains: socket.cljs?rel=1523021762398:71 WebSocket connection to '<ws://localhost:3449/figwheel-ws/app>' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

fmn12:04:57

I might be wrong, have you tried delete the generated js before running the figwheel command again?

Kari Marttila12:04:41

Haven't tried that. Let's try it.

mfikes12:04:52

@kari.marttila Are you using ClojureScript 1.10.238 with :aot-cache enabled? If so ~/.cljs/.aot_cache/1.10.238/*/figwheel/connect.js will have a port number compiled into it.

Kari Marttila12:04:20

[org.clojure/clojurescript "1.10.238"] but there is no :aot-cache (unless the default value is enabled).

mfikes12:04:00

The default for :aot-cache is false (for regular lein-based projects like yours)

fmn12:04:25

@kari.marttila I tried it using lein figwheel template, changing the port several time and it works just okay. What I did is delete the generated js and clear the browser cache

Kari Marttila12:04:08

@funyako.funyao156: Thanks. Tried lein clean and then in Opera (instead Chrome) - and it worked. So, I write to my instructions: If you change the server port, then: 1. lein clean, 2. Clear browser cache, 3. lein figwheel.

Kari Marttila12:04:17

Damn, you guys are great!

Kari Marttila12:04:35

This is a great community! It's really great that you guys help beginners like me. This issue was solved pretty fast (like the previous cors one) as soon as I stopped hitting my head on the wall and instead asked for help in this site. 🙂

Kari Marttila13:04:03

I'm really excited about ClojureScript. I'm an old backend programmer and I have implemented only one SPA using Angular. I never liked Javascript that much. I have implemented one backend microservice using Clojure and loved it. It's exciting to learn ClojureScript so that in the future I can implement frontends to my backend systems using the same familiar great language.

schmee13:04:00

@kari.marttila best of luck! 🙂 I’m also primarily a backend developer but I’ve have managed to cobble together a few frontends using Cljs and Reagent without too much trouble 😄

fmn13:04:58

@kari.marttila Nice! Happy to hear it's working.

ackerleytng14:04:40

i put a clojure server together with clojurescript in the same project

ackerleytng14:04:21

when i try and run figwheel, I get this error

Caused by: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
if i include
[com.novemberain/monger "3.1.0"]

ackerleytng14:04:42

but if i comment it out, lein figwheel runs fine

ackerleytng14:04:06

is there any way to have some dependencies only for the client side?

joelsanchez14:04:41

check the output of lein deps :tree, you'll likely find that you have a conflict

joelsanchez14:04:12

most likely with guava, because monger depends on clojurewerkz/support, which depends on guava 21.0

joelsanchez14:04:22

you'll likely have another thing that needs a more recent guava

ackerleytng14:04:34

oh i see, it does show conflicts

ackerleytng14:04:04

what does this conflict thing mean?

joelsanchez14:04:11

I had to add a [com.google.guava/guava "23.0"] dependency for things to work

ackerleytng14:04:16

does the system pick the oldest?

ackerleytng14:04:19

or the newest?

ackerleytng14:04:39

it picks the newest among all the requirements?

troglotit14:04:42

Hi! Is there any elegant solutions to circular dependencies in namespaces? I couldn’t think of possible refactoring, because symbols themselves depend on each other.

joelsanchez14:04:48

whatever it picks you want to make sure it only has 1 choice, by using exclusions or explicit dependencies

joelsanchez14:04:55

what it picks is not relevant

ackerleytng14:04:16

why doesn't lein just include all of them?

ackerleytng14:04:34

and limit each dependency chain to use its own

joelsanchez14:04:43

try adding the explicit dependency or doing this [com.novemberain/monger "3.1.0" :exclusions [com.google.guava/guava]]

joelsanchez14:04:04

I don't think that's even possible with the JVM

ackerleytng14:04:03

[com.novemberain/monger "3.1.0"] -> [clojurewerkz/support "1.1.0"] -> [com.google.guava/guava "18.0"]
 overrides
[reagent "0.8.0-alpha2"] -> [org.clojure/clojurescript "1.9.946"] -> [com.google.javascript/closure-compiler-unshaded "v20170910"] -> [com.google.guava/guava "20.0"]
 and
[hickory "0.7.1"] -> [org.clojure/clojurescript "1.9.293"] -> [com.google.javascript/closure-compiler-unshaded "v20160911"] -> [com.google.guava/guava "19.0"]
 and
[org.clojure/clojurescript "1.10.238"] -> [com.google.javascript/closure-compiler-unshaded "v20180204"] -> [com.google.guava/guava "22.0"]

Consider using these exclusions:
[reagent "0.8.0-alpha2" :exclusions [com.google.guava/guava]]
[hickory "0.7.1" :exclusions [com.google.guava/guava]]
[org.clojure/clojurescript "1.10.238" :exclusions [com.google.guava/guava]]

ackerleytng14:04:25

it seems like they're recommending me to use the oldest, which is provided by monger?

sveri14:04:06

@troglotit There is no other solution than refactoring your code until you have a clean dependency graph.

joelsanchez14:04:23

even though it recommends the oldest, it's not always the best solution

sveri14:04:26

This might seem hard to do, but it is possible

joelsanchez14:04:35

and, as I said, I had to use the most recent guava, not the oldest, for things to work

ackerleytng14:04:46

i see. thanks!

ackerleytng14:04:48

do you normally resolve all the issues with exclusions, or do you just resolve it if something breaks?

joelsanchez14:04:02

should do the former, tend to do the latter 🙂

ackerleytng14:04:26

haha i see. excluding guava from monger worked for me too

ackerleytng14:04:29

thanks so much!

👍 4
Kevin Beaux15:04:04

Hi, i'm trying to sort an array with elements which can has the key :rank but some elements don't have this key, then i want to sort the elements in first by :rank if they have it and if they don't have it i want to sort them by :id. Can you help me to do that plz ? My first approach here was to do 2 arrays then concatenate them.

ackerleytng15:04:46

do you have an example of the array?

ackerleytng15:04:23

[{:rank 0 :id 2} {:rank 1 :id 3} {:id 9}]?

Kevin Beaux15:04:31

yes that's it

ackerleytng15:04:34

and the expected output is that too?

schmee15:04:52

@kevin.beaux (sort-by (juxt :rank :id) your-array)

ackerleytng15:04:25

hm i think that doesn't work because nil is sorted before a number

ackerleytng15:04:46

anyway the first thing that comes to mind is sort-by

Kevin Beaux15:04:48

[{:rank 0 :id 2} {:rank 4 :id 3} {:rank 1 :id 4} {:id 9} {:id 2} {:id 6}] expected output : [{:rank 0 :id 2} {:rank 1 :id 4} {:rank 4 :id 3} {:id 2} {:id 6} {:id 9}]

ackerleytng15:04:02

maybe sort-by with a custom comparator

schmee15:04:34

did you try the version I posted above?

Kevin Beaux15:04:57

i'm going to try

Kevin Beaux15:04:13

it gives me this result : ({:id 2} {:id 6} {:id 9} {:rank 0, :id 2} {:rank 1, :id 4} {:rank 4, :id 3})

ackerleytng15:04:01

(sort-by (juxt :rank :id) (fn [[ra ia] [rb ib]] (or (and ra rb (< ra rb)) (< ia ib))) [{:rank 0 :id 2} {:rank 4 :id 3} {:rank 1 :id 4} {:id 9} {:id 2} {:id 6}])

ackerleytng15:04:05

maybe something like that

ackerleytng15:04:10

it doesn't work now

ackerleytng15:04:18

but by tweaking the comp function

ackerleytng15:04:25

you could probably get something

Kevin Beaux15:04:51

ok thanks 🙂

Rachna20:04:17

Hello guys: I need your help in following code: I have data like: [{:number "A1", :name "Alex",:Grade "A"} {:number "2", :name "Bob", :Grade "B"} {:number "B2", :name "Cindy", :Grade "C"} ] I need to print all the data which has ':number' pattern as [A-Z][0-9] So the output should be: [{:number "A1", :name "Alex",:Grade "A"} {:number "B2", :name "Cindy", :Grade "C"} ] The pattern matching I am using is: "#(re-matches #"[A-Z][0-9]*" (:number %))" How can I pass the data and get the filtered data based on the pattern matching on :number.

noisesmith20:04:04

@rachna.rajput99 does (filter f v) not return what you want? (where f is your pattern function, and v is your input)

noisesmith20:04:29

you can use (run! println (filter f v)) if all you want is to print it

noisesmith20:04:48

you added parens

noisesmith20:04:56

in clojure, (f) means call f

noisesmith20:04:11

so ((f)) means call the thing f returns if you call it

noisesmith20:04:33

you can't call a lazy seq, and filter returns a lazy seq, you can fix the error by removing the extra parens

noisesmith20:04:17

@rachna.rajput99 if you are familiar with other languages, you can convert f(x) in most languages to (f x) in clojure - the paren does the same thing, it's just in a different position

Rachna22:04:42

@U051SS2EU: this code works: (filter #(re-matches #"[A-Z][0-9]*" (:number %)) [{:number "A1", :name "Alex",:Grade "A"} {:number "2", :name "Bob", :Grade "B"} {:number "B2", :name "Cindy", :Grade "C"} ])

Rachna22:04:48

Thank you 🙂

lgessler22:04:44

Hi everyone, I'm writing my very first macro. I want to generate something like this:

(defn date 
  [hiccup] 
  (-> hiccup hiccup-zip second :date))
from something like this:
(zipfunc date second :date)
This is the closest I've gotten, but it's still not working and I'm not sure where I'm going wrong.
(defmacro zipfunc
  [fname & xs]
  `(defn (quote fname)
         [hiccup#]
         (-> hiccup# hiccup-zip ~@xs)))

seancorfield22:04:53

@lgessler Pretty sure you want ~fname instead of (quote fname) since you want the value of fname as the name of the function.

seancorfield22:04:38

Depending on which namespace hiccup-zip is in, you may need to use the fully-qualified symbol name there.

lgessler22:04:24

Hmm... OK, so here's what I have in my file (hiccup-zip is defined in the same file/namespace, just a bit above this macro definition):

(defmacro zipfunc
  [fname & xs]
  `(defn ~fname
         [hiccup#]
         (-> hiccup# hiccup-zip ~@xs)))

(zipfunc date second :date)
CLJS points to date in the last line and says "Use of undeclared var ewan.spec.eaf30/date". I'm puzzled, because that makes it seem like cljs is trying to evaluate the args to a macro, which of course it's not supposed to do for macros

seancorfield23:04:29

And what is that date function supposed to signify (in terms of a fully-qualified symbol)?

lgessler23:04:49

My intent is to have it be defed inside of ewan.spec.eaf30 (ie, the current ns)

lgessler23:04:43

just like (defn fname [...]) defs fname inside of the current ns

seancorfield23:04:04

Oh, sorry, yes, I misread the call.

seancorfield23:04:53

Are you trying to evaluate zipfunc in the REPL or is it in the file?

seancorfield23:04:40

Macros are a bit strange in cljs -- you have zipfunc in a .cljc or .clj file, right? Not .cljs.

seancorfield23:04:55

(I don't use cljs at all)

lgessler23:04:37

Oops, that must be the problem--I forgot about that. This is all in a cljs file

noisesmith23:04:06

that would be the issue - a macro and it's usage can't be in the same "compilation unit" in cljs

seancorfield23:04:11

I think that is your problem then: I believe that if you try to define a macro in a .cljs file, it is treated as a regular function instead.

noisesmith23:04:46

even with self-hosting cljs, it doesn't work to define and use in the same ns