Fork me on GitHub
#clojure
<
2017-08-23
>
ghadi00:08:07

clojure has a repl defined in clojure.main. It is simply R - E - P - L, it doesn't do autocompletion or stuff like that. If you run lein run -m clojure.main you can see it. lein and boot wrap nREPL, which is an RPC-oriented repl that has a bunch of bells and whistles like autocompletion

juanjo.lenero00:08:30

That explains why I ran into some issues when trying to attach to a boot repl from cider I guess

ghadi00:08:49

These days, I work on a bare clojure REPL, but I have been working with and on clojure for 7 or 8 years

ghadi00:08:58

I'm over nREPL.

ghadi00:08:44

But, I do tab completion with my editor, not with my repl

ghadi00:08:09

I don't really type into the REPL too much. I let my editor paste stuff in for me

juanjo.lenero00:08:10

I’ll try to keep it simple and focus on learning and doing side-projects before diving into all of this 😅

juanjo.lenero00:08:27

many repls + many build tools is overwhelming right now

ghadi00:08:31

Good call. lein i think will be easy enough.

juanjo.lenero00:08:48

thanks for clearing that up

ghadi00:08:08

n.p. it's hard to find a summarized history in one place

ghadi00:08:16

I hope that lein and boot eventually adopt the dependency notation from tools.deps.

seancorfield01:08:12

@juanjo.lenero Given where you are on the learning curve, you'll probably benefit from the #beginners channel -- that's a great place to ask for help when getting your head around the basics of boot or lein or the JVM or the classpath. This channel tends to assume a certain level of knowledge about those things which can sometimes confuse folks asking questions more than it helps them.

seancorfield01:08:22

(and a meta note to folks who've been here a while: the admins recently updated the list of channels that new Clojurians auto-join to include #beginners because it seems like a lot of new folks have been joining lately and many of them seem to be in the early stages of exploring Clojure rather than already ramped up)

tjscollins02:08:58

Having a problem with declaring a protocol, wonder if anyone can help?

(defprotocol cron-job
  (schedule [f s] "Calls a function on a schedule")
  (unschedule [f] "Removes a function from the schedule"))

(extend-type clojure.lang.IFn
  cron-job
  (schedule
    [f s]
    (let [s-key (-> s var meta :name keyword)
          s-fns (get @(jobs) s-key)
          f-key (-> f var meta :name keyword)]
      (if (some? (get s-fns f-key))
        (throw (Exception. (str "Function already scheduled to run " s-type)))
        (swap! jobs (fn [a]
                      (assoc a s-key
                             (assoc s-fns f-key (s f))))))))
  (unschedule [f]
    ""))
When I try to compile I get an error Unable to resolve var: s in this context, which doesn't make sense to me. It's one of the arguments to schedule. Is my syntax for a protocol method with multiple arguments wrong?

didibus03:08:55

@tjscollins I think its because of the thread-first macro. It expands to (keyword (:name (meta #'s)))

didibus03:08:22

If you replace it with (keyword (:name (meta s))) it works.

didibus03:08:56

Or just remove var from the threading chain

tjscollins05:08:59

After toying around with it some more, the best solution seems to be not bothering with creating keywords at all and just using the arguments f and s (they are both functions) as map keys directly. Since the jobs atom is private to the name space it really didn't matter what the keys were so long as I could get reliably generate them from the function. The simplest way seems to be to just use the function directly. Had forgotten you could use functions as keys. Thanks for the help.

xtreak2906:08:05

Is there a way to pretty print only the spec in cider repl while passing wrong arguments to an instrumented function?

zilti07:08:14

Could someone help me with my core.logic problem? I want to get all possible answers of one goal, is this possible? Basically what I have now is:

(defn next-free-license [ltype]
  (run 1 [q]
       (fresh [licid tid link links license]
              (datascript= [tid :type/name ltype])
              (datascript= [licid :license/type tid])
              (datascript= [licid :license/key license])
              (datascript= [licid :license/user link])
              (membero link links)
              (== q [links licid license]))))
Which gets me [(138 . _0) 6 "532f16c2c9b13540eb6a"] but I need [(138 143 151 153) 6 "532f16c2c9b13540eb6a"].

seb23110:08:12

Hello does anyone know a decent short description tutorial for setting up a Clojure project as an app to run from the command line. I’ve kind of done it before, but wanted to have something like a checklist of things to ensure I’ve done, I think mainly it is defining params in the project.clj

rod10:08:50

seb231: If you use lein new it'll create a project skeleton (including project.clj), you'll then need to add (:gen-class) and :main to get it to start from lein run or an uberjar - https://yobriefca.se/blog/2014/03/02/building-command-line-apps-with-clojure/

martinklepsch11:08:54

Hey - looking for something like core.medley/distinct-by but where the later items “win” http://weavejester.github.io/medley/medley.core.html#var-distinct-by (can’t use set because I need the -by bit)

xtreak2911:08:51

@martinklepsch Something like this https://pastebin.com/NkkgYLk1 ? It doesn't support transducers and work like core.medley/distinct-by

martinklepsch11:08:17

@xtreak29 that’s a nice idea but unfortunately the group-by call removes any sorted-ness

martinklepsch11:08:08

but I guess I can just sort it again 🙂

andrethehunter12:08:09

Why does ({:a 1 :b 2} :a) work? I thought the first parameter had to be a function or keyword

martinklepsch12:08:24

@andrethehunter maps implement the “function interface” IFn which allows them to be used as functions as well

martinklepsch12:08:51

@andrethehunter same is true for (#{1 2} 2) as well (probably some more)

zilti12:08:42

Hmm can I "force-ground" an lvar?

pwrflx12:08:17

anyone has an example of using figwheel together with pedestal? My specific problem is, that in the project.clj there is the key :ring-handler, which I'm not sure how to set up in case of pedestal

mx200012:08:43

Hi, I found a nice example CRUD web application using compojure, enlive, datomic, clojurescript

mx200012:08:05

Its from 2013. Are there also some newer examples?

ingesol13:08:17

It seems that if I change my clojure.spec "s/def" code while running lein-test-refresh, the tests don't pick up the changed spec definition. Do any of you know why? Is this as intended?

Alex Miller (Clojure team)13:08:06

depends how much stuff is getting reloaded. I’m not sure what lein-test-refresh does

ingesol14:08:46

I didn't check either. Probably does not refresh specs. I guess I can try REPL-based refresh with some other tool instead

jakemcc14:08:32

lein-test-refresh uses tools.namespace for doing all of its reloading

jakemcc14:08:39

I (author of test-refresh) haven’t started using spec yet, so can’t really comment on why they might not be loading. tools.namespace readme has some gotchas with using tools.namespace for reloading If you create a minimal example and have write out some steps to reproduce and post as an issue on lein-test-refresh I might be able to carve out some time to look at it.

ingesol14:08:03

Will do, thanks!

ingesol10:08:24

In the process, I found that this issue might not be related to test-refresh at all. Regular spec'ing of functions works just fine with instrumentation. But when specs are referenced through compojure-api, they don't reload any more. Usually this would be caused by a mistake I made, but I can't seem to find it.

ingesol10:08:22

Closing issue, as I'm pretty sure this is my fault. No surprise there 🙂 Thanks for the help guys!

codefinger13:08:07

I think you'll want to use JDBC_DATABASE_URL here because Hikari doesn't recognize the postgres:// URI format the way other clojure libs do.

motbsitu15:08:26

Hello Clojurians! I am gearing up to organize a ClojureBridge MN “ClojureBridge aims to increase diversity within the Clojure community by offering free, beginner-friendly Clojure programming workshops for underrepresented groups in tech.” http://clojurebridgemn.org/ http://www.clojurebridge.org/ Who is interested in helping me organize the event? I am looking for a couple of board members to help out. I am guessing 3-4 hrs per month for maybe 3 months or so, then the event itself, which includes a Friday evening and a whole day Saturday. I don’t know dates yet. Let me know if you are interested or know someone who is. Thank you!

misha16:08:57

which is more idiomatic: 1️⃣ nested reduces, or 2️⃣ loop with many bindings, and a tall case/cond`, or maybe even 3️⃣ tree-seq/walk with a weird node function? 0️⃣ it does not matter

noisesmith16:08:43

3.5) walk with a multimethod as the node function

noisesmith16:08:27

or make that a reduce over tree-seq calling the multimethod if you need a final accumulated result based on certain leaves / nodes

misha16:08:43

basically trying to walk this thing:

{:c #{[:j :k]}
   :a #{[:b :c]}
   :b #{[:d :e :f] [:g :h]}})

noisesmith16:08:55

and do what with what you find?

misha16:08:53

I'll look at the 3.5, so far 1 and 2 are ok, but a bit gauche(?)

noisesmith16:08:35

I can give a concrete example if you give some hint about what you actually want to do with that structure

misha16:08:51

@noisesmith keywords are states, vectors are regions. Need to end up with map like:

{:c {:parent :a
       :region 1
       :regions #{0}
       :kids #{:j :k}}
   0 [:j :k]
   ...}

noisesmith16:08:17

how do you get 0 ?

misha16:08:35

(let [!id (atom -1)
      next-id #(swap! !id inc)]
opieop

misha16:08:52

when I see next region, I inc id, and use it until next one (obviously, suits reduce. would use binding for the loop instead)

noisesmith17:08:57

I would never use an atom for a value in a reduce - just use a hash-map accumulator and make the id counter one of the keys

noisesmith17:08:49

so I take the multimethod / tree-seq suggestion back, that isn’t helpful to this problem at all

misha17:08:50

yeah, that (atom) smells, I agree.

noisesmith17:08:11

it’s best fixed as a series of reduces, not nested but sequential

noisesmith17:08:28

(each using the output of the one before)

misha17:08:00

how is it better than 3 nested reduces? apart from being not nested :)

noisesmith17:08:26

because your problem is simpler if you have separate reducing steps and each one can see the entirety of the result of the previous

noisesmith17:08:54

instead of nested reduces that can’t see things that aren’t accumulated yet from other inputs

hiredman17:08:10

that looks like a graph, I bet you could do it with a single reduce if you did a topo sort first, so you only encountered a key after all its children have been encountered

noisesmith17:08:41

I was concerned that it could be a general graph, and that wouldn’t handle loops

noisesmith17:08:51

if it isn’t going to have loops, I agree with @hiredman that is simplest

misha17:08:11

@hiredman it is a graph. I just don't know how sorting and then 1 reduce would be better than 3 short nested ones. Readability? The task is not (that) hard, I just want to see if there is a noticeably better implementation than 3 short reduces

misha17:08:07

@noisesmith it should not have loops. but it is my duty kappa to throw/notify user, in case there are any

noisesmith17:08:47

in that case you can topo-sort, and throw an error if the topo-sort finds a loop?

misha17:08:48

rules are: no loops, no multiple parents. But I need to validate that input actually follows those.

noisesmith17:08:16

if you are doing that validation, you might as well topo-sort while doing it

noisesmith17:08:21

and that does simplify the reduce

misha17:08:27

I'll look into it then, thanks. But isn't it slower?

noisesmith17:08:17

Slower than multiple nested reduces? You’d have to measure that. Remember this lets you skip the extra nesting, and the separate structure validation (since it can be a part of the sort automatically)

misha17:08:32

I mean, I can verify there are no loops/multiple parents while doing 3-nested-reduces :)

noisesmith17:08:26

but topo-sort as a seperate step has the advantage of being a well known thing with well known algorithms - it’s a clear separate step that a reader can understand. And it isolates a bunch of extra complexity out of the other code if used properly.

noisesmith17:08:46

eg. putting structure validation inside your value accumulation leads to something much harder to read

misha17:08:03

that is true.

juanjo.lenero17:08:09

@seancorfield Got it, I missed the #begginers channel but I’m there now, thanks for the suggestion.

joshjones18:08:40

I met a guy downstairs in our cafeteria today at lunch who walked up to me like he knew me, giving me high fives. Thinking this person had mistaken me for someone else, I started to tell him he had the wrong guy, and then he said, “dude, I LOVE clojure!” He had seen my clojure t-shirt I was wearing. Turns out we work on the same floor even, but in different areas which are not connected. He was surprised to find that my team is basically 100% clojure now, and I think he wants to move over here and work with us 🙂 Just wanted to pass it along; I think we can all appreciate stories like this one. clj cljs

PB19:08:27

Hey all. I have a friend interested in getting into clj. WHere woudl you point him? Braveclojure?

oarim19:08:44

@petr I've found that Brave is the best to introduce someone to clj, other resource could be The Joy of Clojure

PB19:08:37

@oarim Thank you!

PB19:08:56

I also read Clojure programming. Are there other beginnerish friendly books?

joshjones19:08:51

Programming Clojure (still beta) is good. Living Clojure is also a reasonably gentle introduction. Clojure Programming is not a particularly beginner-friendly book IMO — it’s almost 600 pages of small-ish type, and probably my favorite clojure book due to the fact that it is incredibly thorough and covers so much detail — but that is also the reason why I don’t think it’s very beginner-friendly

PB19:08:21

Programming clojure was a great book. Althoguh I’ll admit I struggled at first

joshjones19:08:30

yeah, it’s just awesome — but not something i’d hand to a beginner i’d say online Brave and True book right next to a terminal with a REPL open is a great way to start. As with anything, learning/reading must be coupled with pretty immediate action and repl-driven is a great way to interact with a new language

schmee19:08:55

@petr how experienced of a programmer is your friend?

PB19:08:19

He coudl be considered high mid level

PB19:08:35

No lisp or pure functional experience though

schmee19:08:43

ok, then I can recommend The Joy of Clojure 🙂

seancorfield19:08:21

Joy... is a great book but not a good intro for anyone who doesn't already know some Clojure -- or has some FP/Lisp in their background.

PB19:08:25

What talks would you recommend?

seancorfield19:08:07

Does your friend have Java chops?

PB19:08:51

I’d go with that he has a little

seancorfield19:08:03

For someone with some Java background, Rich's Clojure for Java Developers Part 1 is good https://www.youtube.com/watch?v=P76Vbsk_3J0

PB19:08:22

That’s great! THank you

tjtolton21:08:26

anyone know of an easy as hell naive way to parse xml into a key-val map and throwing out attrs?

tjtolton21:08:12

xml/parse gives all that :tag :attrs :content noise

tjtolton21:08:13

yeah okay I'll just use the zipper like a grown up.