This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-23
Channels
- # beginners (55)
- # boot (37)
- # braid-chat (1)
- # chestnut (3)
- # cider (4)
- # clara (22)
- # cljs-dev (54)
- # cljsrn (3)
- # clojure (114)
- # clojure-italy (12)
- # clojure-losangeles (3)
- # clojure-portugal (1)
- # clojure-russia (1)
- # clojure-spec (30)
- # clojure-uk (67)
- # clojure-ukraine (1)
- # clojurescript (101)
- # core-async (11)
- # cursive (6)
- # data-science (27)
- # datomic (8)
- # figwheel (3)
- # fulcro (59)
- # graphql (2)
- # hoplon (89)
- # jobs (3)
- # jobs-rus (1)
- # leiningen (3)
- # lumo (19)
- # off-topic (9)
- # om (48)
- # pedestal (2)
- # portkey (4)
- # protorepl (19)
- # re-frame (13)
- # reagent (38)
- # remote-jobs (1)
- # ring-swagger (4)
- # spacemacs (10)
- # specter (2)
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
That explains why I ran into some issues when trying to attach to a boot repl from cider I guess
These days, I work on a bare clojure REPL, but I have been working with and on clojure for 7 or 8 years
I’ll try to keep it simple and focus on learning and doing side-projects before diving into all of this 😅
many repls + many build tools is overwhelming right now
thanks for clearing that up
@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.
(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)
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?@tjscollins I think its because of the thread-first macro. It expands to (keyword (:name (meta #'s)))
Bingo. Thanks @didibus .
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.
Is there a way to pretty print only the spec in cider repl while passing wrong arguments to an instrumented function?
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"]
.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
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/
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)
@martinklepsch Something like this https://pastebin.com/NkkgYLk1 ? It doesn't support transducers and work like core.medley/distinct-by
@xtreak29 that’s a nice idea but unfortunately the group-by call removes any sorted-ness
but I guess I can just sort it again 🙂
Why does ({:a 1 :b 2} :a)
work? I thought the first parameter had to be a function or keyword
@andrethehunter maps implement the “function interface” IFn
which allows them to be used as functions as well
@andrethehunter same is true for (#{1 2} 2)
as well (probably some more)
@xtreak29 that's it! Thanks
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
Hi, I found a nice example CRUD web application using compojure, enlive, datomic, clojurescript
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?
depends how much stuff is getting reloaded. I’m not sure what lein-test-refresh does
I didn't check either. Probably does not refresh specs. I guess I can try REPL-based refresh with some other tool instead
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.
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.
Closing issue, as I'm pretty sure this is my fault. No surprise there 🙂 Thanks for the help guys!
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.
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!
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
3.5) walk with a multimethod as the node function
or make that a reduce over tree-seq calling the multimethod if you need a final accumulated result based on certain leaves / nodes
basically trying to walk this thing:
{:c #{[:j :k]}
:a #{[:b :c]}
:b #{[:d :e :f] [:g :h]}})
and do what with what you find?
I can give a concrete example if you give some hint about what you actually want to do with that structure
@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]
...}
how do you get 0
?
when I see next region, I inc id, and use it until next one (obviously, suits reduce
. would use binding for the loop
instead)
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
so I take the multimethod / tree-seq suggestion back, that isn’t helpful to this problem at all
it’s best fixed as a series of reduces, not nested but sequential
(each using the output of the one before)
because your problem is simpler if you have separate reducing steps and each one can see the entirety of the result of the previous
instead of nested reduces that can’t see things that aren’t accumulated yet from other inputs
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
I was concerned that it could be a general graph, and that wouldn’t handle loops
but yeah
if it isn’t going to have loops, I agree with @hiredman that is simplest
@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
@noisesmith it should not have loops. but it is my duty to throw/notify user, in case there are any
in that case you can topo-sort, and throw an error if the topo-sort finds a loop?
rules are: no loops, no multiple parents. But I need to validate that input actually follows those.
if you are doing that validation, you might as well topo-sort while doing it
and that does simplify the reduce
I happen to have a gently used toposort https://gist.github.com/hiredman/075b45eaeb01e4b526ce6f8854685487#file-ur-component-clj-L1-L10
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)
I mean, I can verify there are no loops/multiple parents while doing 3-nested-reduces :)
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.
eg. putting structure validation inside your value accumulation leads to something much harder to read
thank you @noisesmith @hiredman
@seancorfield Got it, I missed the #begginers channel but I’m there now, thanks for the suggestion.
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.
Hey all. I have a friend interested in getting into clj. WHere woudl you point him? Braveclojure?
@petr I've found that Brave is the best to introduce someone to clj, other resource could be The Joy of Clojure
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
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
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.
Rich's Simple/Easy https://www.infoq.com/presentations/Simple-Made-Easy and Are We There Yet? https://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey come to mind...
Does your friend have Java chops?
https://aphyr.com/tags/Clojure-from-the-ground-up is good as well
For someone with some Java background, Rich's Clojure for Java Developers Part 1 is good https://www.youtube.com/watch?v=P76Vbsk_3J0