This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-24
Channels
- # beginners (19)
- # boot (118)
- # capetown (4)
- # cider (37)
- # cljs-dev (69)
- # cljsjs (23)
- # clojure (212)
- # clojure-austin (10)
- # clojure-india (3)
- # clojure-italy (2)
- # clojure-mke (1)
- # clojure-nl (1)
- # clojure-russia (5)
- # clojure-spec (52)
- # clojure-uk (86)
- # clojurescript (31)
- # core-async (9)
- # cursive (123)
- # datomic (91)
- # emacs (22)
- # events (3)
- # hoplon (68)
- # klipse (4)
- # lambdaisland (10)
- # leiningen (2)
- # off-topic (14)
- # om (14)
- # onyx (44)
- # perun (14)
- # proton (20)
- # re-frame (15)
- # reagent (10)
- # ring-swagger (9)
- # specter (18)
- # untangled (3)
- # vim (26)
- # yada (4)
@pelletier the whole point of with-redefs is that it’s not thread-local. all vars would be :dynamic by default if it were fast enough
gotcha. i reckon the actual way to go is to encapsulate away our side effects and avoid the redefs (or binding) altogether
@pelletier that should always be the goal 😜
If there’s anyone here who uses Expectations and isn’t already in the #expectations channel, I just announced there that work on adding “`clojure.test` compatibility” will start this week (with a link to the GitHub issue discussing it). If you are interested in that, please either join #expectations or read / watch the GitHub issue (#82).
I can't remember where I read it, or maybe i'm just remembering, but for some reason I recall something about clojure recur not being nestable
for instance if i had two async/go-loop, one inside the other, can that actually work?
@bcbradley you probably can't have them inside each other in the same lexical scope, as which recur would recur refer to in that scenario?
when it says "provides the recur special operator, which does constant-space recursive looping by rebinding and jumping to the nearest enclosing loop or function frame" at https://clojure.org/about/functional_programming is that precise?
does java have a notion of "with-current-directory" where it (1) goes into the dir (2) execs some stuff, then (3) pops out? or do I have to manage the directory stack myself?
@borkdude I just realized I caught the wrong exception. I created a new problem instead of catching the orignal problem. I will keep looking at xml/parse-str
.
@qqq Not a java expert, but the situation looks like a mess: http://stackoverflow.com/questions/840190/changing-the-current-working-directory-in-java
@beppu: thanks! In that case, is it possible to say "execute this shell command, with the current directory as" ?
so I'm no longer requiring to change the wrking direcotry of my entire jvm; I just want a particular shell command to be executed with the working directory being something else
@qqq I was playing around in the repl and this worked for me: http://stackoverflow.com/a/38517391/493051
(use '[clojure.java.shell])
(sh "ls")
(binding [*sh-dir* "/usr"] (sh "ls"))
Hey everyone, I’ve been trying to make a simple game, but stuck at this step. I’m trying to return a new state
in the following way, but doing this causes the game to be really slow.
I thought that the m x n
for loop is the problem but the other example, seems to suggest that this isn’t the case. In idea what’s wrong?
when you say it’s slow, one iteration is slow or it slows down as the game progresses?
@cgrand the slows down the game progress, so the game is like space invaders… as long as there’s one drop traveling the game, its fine.. but when it gets to two drops,, the game almost halts..
could you trace state
(or at least the number of items under keys :flowers
and :drops
)?
if you have 6 flowers and 2 drops at the start, first iteration gives you 12 and 2, then 24 and 2, then 48 and 2
does this explain the problem?
(for [f [1 2 3 4 5]
d [:a :b]]
f)
=> (1 1 2 2 3 3 4 4 5 5)
Also, now if i want to keep both the drops and the flowers that dont intersect, is there a better way than calling that for loop twice?
Here's something weird (well, to me, it's weird)... I have a line: (satisfies? clojure.core.async.impl.protocols/ReadPort ch)
in my code that does work when I run my code normally (`boot run`). However, when I do check-sources
, throws an error:
$ boot check-sources
WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: clojure.tools.analyzer.utils, being replaced by: #'clojure.tools.analyzer.utils/boolean?
WARNING: boolean? already refers to: #'clojure.core/boolean? in namespace: clojure.tools.analyzer, being replaced by: #'clojure.tools.analyzer.utils/boolean?
clojure.lang.ExceptionInfo: java.lang.ClassNotFoundException: clojure.core.async.impl.protocols, compiling:(...)
data: {:file "/tmp/boot.user5239864754805408740.clj", :line 63}
clojure.lang.Compiler$CompilerException: java.lang.ClassNotFoundException: clojure.core.async.impl.protocols, compiling:(...)
java.lang.ClassNotFoundException: clojure.core.async.impl.protocols
...
clojure.core/load/fn core.clj: 5893
clojure.core/load/invokeStatic core.clj: 5892
clojure.core/load core.clj: 5876
...
clojure.core/load-one/invokeStatic core.clj: 5697
clojure.core/load-one core.clj: 5692
clojure.core/load-lib/fn core.clj: 5737
clojure.core/load-lib/invokeStatic core.clj: 5736
clojure.core/load-lib core.clj: 5717
...
clojure.core/apply/invokeStatic core.clj: 648
clojure.core/load-libs/invokeStatic core.clj: 5774
clojure.core/load-libs core.clj: 5758
...
clojure.core/apply/invokeStatic core.clj: 648
clojure.core/require/invokeStatic core.clj: 5796
clojure.core/require core.clj: 5796
...
yagni.namespace/prepare-namespaces/invokeStatic namespace.clj: 14
yagni.namespace/prepare-namespaces namespace.clj: 7
yagni.core/construct-reference-graph/invokeStatic core.clj: 32
yagni.core/construct-reference-graph core.clj: 26
...
pod$eval1107$fn__1108.invoke NO_SOURCE_FILE
pod$eval1107.invokeStatic NO_SOURCE_FILE
pod$eval1107.invoke NO_SOURCE_FILE
...
clojure.core/eval/invokeStatic core.clj: 3105
clojure.core/eval core.clj: 3101
boot.pod/eval-in* pod.clj: 437
...
boot.pod/eval-in* pod.clj: 440
tolitius.checker.yagni/check/invokeStatic yagni.clj: 36
tolitius.checker.yagni/check yagni.clj: 33
tolitius.boot-check/eval257/fn/fn/fn boot_check.clj: 44
boot.core/run-tasks core.clj: 938
boot.core/boot/fn core.clj: 948
clojure.core/binding-conveyor-fn/fn core.clj: 2019
It's not onlywith check/with-yagni
but also on running check/with-kibit
check/with-eastwood
gives something similar:
Got exception with extra ex-data:
msg='No such namespace: clojure.core.async.impl.protocols'
(keys dat)=(:ns :form :file :end-column :column :line :end-line)
(:form dat)=
^{:line 33} clojure.core.async.impl.protocols/ReadPort
ExceptionInfo No such namespace: clojure.core.async.impl.protocols
clojure.core/ex-info (core.clj:4617)
clojure.core/ex-info (core.clj:4617)
...
check/with-bikeshed
seems to have problems finding datomic, I do get a bunch of:
Unable to parse ...: java.io.FileNotFoundException: Could not locate datomic/api__init.class or datomic/api.clj on classpath., compiling:(...:1:1)
so well, why is boot-check not finding some files/namespaces? (which seems to be the problem)
@kurt-yagram Try adding a :require [clojure.core.async.impl.protocols]
to the ns
form
seems to work... funny. Thanks
memoizing only after x times... here's the use case: there is a call that takes some time. However, after a number of calls, it stabilizes, meaning: the first few calls, the result changes, but after that, it's always the same. I only found out now 🙂. So, since it's a pretty heavy call, I memoized it:
(mem/lru fn
(cache/ttl-cache-factory {} :ttl ttl)
:lru/threshold max-in-cache)))
However, it would be better only to memoize it after x calls with the same arguments... any ideas of how to implement this?- or even better: changing ttl of an entry based on the number of times it's called.
it basically fetches data from external resources: I push data to an external resources, and from that moment, I can fetch a 'result' from it. The first few calls, the 'result' may still be changing, after about 3-5 calls, the 'result' is stable (enough for memoization)
I need to have an variable in a profile and not I others so, I set it in profiles in project.clj but when I read it with environ it casts the boolean to string. What's the correct way of handling booleans?
does anyone know how to dispatch any possible value in multimethods? I mean:
(defmethod foo [:some-val _ _])...
(defmethod foo [:some-val :bar _])...
(defmethod foo [:some-val :bar :baz])...
talking more precisely, I have map with :name
and :version
fields. At first, I'd like to dispatch by the name, but in addition to be able to dispatch by version
that's not how it works
you probably want to take a look at core.match
you need to specify an exact value to dispatch on in defmethod
you seem to be looking at the wrong solution to your problem
you can use hierarchies, right 🙂
I don't think I've seen hierarchies used in the wild
my advice is to start simple when you're writing your first multimethod 🙂
(derive ::_ ::42.0.2)
or something like that? Never use it...
@igrishaev Wouldnt recommend to use it but: https://clojuredocs.org/clojure.core/defmulti#example-57558046e4b0bafd3e2a0474
I wish good old scheme generics with predicates were here...
(defmulti (eq "some-name") (any?))....
(defmulti (eq "some-name") (eq? "42.0.3"))....
@igrishaev multimethod dispatch is not pattern matching
@rauh that does not answer the question. @bronsa yes, that might work: pass a quoted pattern and then match it in dispatch
Hello! Good morning! I have a question. What is the best library of migrations in clojure?
@lhmariano It depends what you want in a migrations library, but I’ve been pretty happy with migratus so far — part of the luminus web app stuff but could be used alone.
anyone using Franzy? I'm confused by the example scripts - they use 0.0.2-SNAPSHOT which I don't have access to (I'm assuming this is to do with the :repositories config that I haven't replicated? - they also use a couple methods (e.g. subscribe-to-partitions) I don't appear to have access to and I'm not sure how to provide it or if this is related to the first issue and I'm wasting my time with this.
i'm quite new to clojure. is anyone able to provide a succinct description of a transducer? are they analogous to anything in java?
if you're new to clojure, you may not need transducers. They're kind of an advanced feature
not very helpful I know 🙂 I can't explain transducers well so I'll leave that to others, but I do know that I don't typically need them in my day to day work
think of the middleware pattern from web applications, but applied to collection transformations. transducers compose a sequence of transformations into a single function, that can then be used with many categories of collections - lazy seqs, sets, streams, channels
because it makes a function, it means you can make the transducer once, and reuse it with multiple collections or collection categories
so... a tranducer is like something i could supply to a threading macro and then pass a collection to?
(-> my-collection (filter #(> % 2)) (even?) ...)
(filter #(> % 2)) is a tranducer?
@pesterhazy yeah i guess they're advanced, haven't needed them so far. kept seeing them in the docs (returns a transducer) and was curious 🙂
threaded (->> (range 10) (map inc) (filter even?))
eager transduced (into [] (comp (map inc) (filter even?)) (range 10))
lazy transduced (sequence (comp (map inc) (filter even?)) (range 10))
the call to comp
can be lifted to a def
and reused:
(def xform (comp (map inc) (filter even?)))
eager transduced (into [] xform (range 10))
lazy transduced (sequence xform (range 10))
@ben.mumford (filter #(> % 2))
is a transducer, but not when it’s inside a threading macro call. filter with one arg - a function - is a transducer that can be applied to a collection later. a threading macro would inject a second arg, causing the filter op to happen immediately
the threaded example above, with the threading removed, is (filter even? (map inc (range 10)))
ah i see
is it similar to a partial function then?
to echo what @pesterhazy said, though, you can totally never use these and get along just fine. but if you learn them and use them, your code will run faster 🙂
(you must be tearing your hair out! sorry for being dumbass!)
yes, similar-ish. in the sense in that you’re capturing some stuff to be applied later
not tearing my hair out 🙂 i love teaching
you'll get nonsensical results if you try to use a transducer as if it was a curried version of that function
could you elaborate please?
how is it different?
@ben.mumford if you're more familiar with JavaScript, there's this post I've read some times ago that is a good starting point. It links to a longer Clojure based post on tranducers.
google says transducers don't create the intermediate collections
https://medium.com/@roman01la/understanding-transducers-in-javascript-3500d3bd9624
@ben.mumford i highly recommend watching Rich’s talks on this stuff
let it soak in a bit 🙂
cheers pal
this is a most useful resource!
@ben.mumford http://elbenshira.com/blog/understanding-transducers/ this page does a good job at deriving transducers, would recommend
Ended up clicking around on that website and ended up at http://elbenshira.com/blog/the-end-of-dynamic-languages/. Not a good idea 😛
> - This could be the end of Dynamic Languages. > - But I just got Dynamic Languages! > - And now, you must save it! Dynamic Languages Panda 2
Yeah, there's plenty of people on the other side of that argument, lol
Never forget, the network is untyped, the moment you talk to something over a wire all your static typing is gone.
@tbaldridge: http://haste-lang.org/pubs/haskell14.pdf would disagree
They can disagree all they want, I can always send garbage down a TCP socket
@prakhar @arnaud_bos I guess I need to link this again....what it would take to get me to "want" a type system again: https://gist.github.com/halgari/f431b2d1094e4ec1e933969969489854
Hint, it's basically spec + typed clojure
Yeah, was about to mention spec too
Cool thing is that you can get it if you want to
@tbaldridge: how much does someone have to pay cognitect for cognitect to build that?
https://circleci.com/blog/why-were-no-longer-using-core-typed/ http://typedclojure.org/ etc
thanks for the link @tbaldridge. Not to get a discussion started on this, but as mentioned in that article, how do you generally deal with the uncertainty? the kind that the author has mentioned
the rabbit hole can get pretty deep https://github.com/hraberg/shen.clj
http://www.shenlanguage.org/learn-shen/#10 Sequent Calculus
@prakhar spec helps a lot, but I'd say what also helps a lot is keeping the data model simple. A map with 100 keys and values is going to be a mess no matter what you try. But naming conventions, namespaced keywords, etc. All help with that.
@prakhar also, keeping structures as flat as possible is good, I'd rather 20 keys in 1 map then a tree of 10 maps with two keys in each.
speaking of namespaced maps, has anyone run into this error where newlines in namespaced maps break the repl reader? it’s happening for me in leiningen repl and clojure-inf https://github.com/clojure-emacs/inf-clojure/issues/39
Yeah, I'm pretty sure that's a bug in some of the nrepl code.
thanks for the tips, @tbaldridge!
@wei I'm going to try that at a bare CLJ repl without lein
@wei, yep, not a problem in Clojure, must be something wrong with lein or some other tool
@tbaldridge ok good to know, thanks for testing that out
anyone got any tooling for cursive intellij or otherwise that would help pick up typos in keywords?
I didn't find it too noisy, basically in line with other source code quality analysis tools
yeah I've tried it before, basically the problem was it always had quite a lot of false positives, which at that point means it doesn't get used. it does seem to have gotten a lot better though
@bfabry I’ve been planning to implement that inspection basically as described in the Eastwood docs. There’s not much more you can do unfortunately, except spec of course.
yeah the keyword typos thing sounds reasonable, it'd be good to be able to run it without mixing with reflection warnings though, and I'll have to figure out what I can change to make things like this not show up
src/link_dataflow/classic/tickets.clj:1:1: keyword-typos: Possible keyword typo: :brands instead of :brand ?
src/link_dataflow/classic/tickets.clj:1:1: keyword-typos: Possible keyword typo: :submitter-id instead of :submitter_id ?
probably spec will help there as those keys will get different namespaces and be repeated at least in their spec somewhere down the line
trying to serve a generated PNG via ring... ring is failing to coerce body of OutputStream, BufferedWriter, and byte[]. what do you guys use?
it’s better to just ask than ask to ask ;)
either is fine though
the mailing list has the benefit of reaching more people, but asynchronously, and with a slightly more reliable archive
this has the benefit of immediacy
thanks alex. more specifically: noob stuff. i'm running into the usual resistance at work - a python guy actually complained about all those parens yesterday. mailing list is better for that sort of thing? i.e. how to not strangle people, easevthem in, etc. the slack channel seems more suited for, well, sth other than that. maybe a newbie channel would be useful?
If any of your coworkers have a history of scheme/commonlisp or other less OO languages winning them over might be advantageous.
unfotunately that is not the case. the programmers seem interested - clojure is at least a little bit sexy. the python guy is a data scientist. nice guy, but maybe not a language geek.
Do you need the data science guy to be on board? Or is it possibly something were you can split concerns and use python for that part
@mobileink how are you approaching the problem? typically huge rewrites / risky projects are met with more resistance (with good reason) than smaller less risky projects
in my experience you're never going to convince the data science guys to like clojure. python is much more than the language to them, it's an entire giant toolchain that all their skills are built around. I would not start there
@esanmiguelc small, very small. iot stuff, with some backend server stuff. bot crazy enuff to suggest a wholesale switch to clj. 😉
Hmm.. I would try to shift the conversation in a way that makes it seem that he doesn’t see the advantageous. Like functional programming is more modular and lends itself to be refactored much easier than imperative code. It might not be things that matter to him but it’s important from the development side.
that's an unfortunate people problem. you're probably best off ignoring it and not responding. I dunno that people who go around bad mouthing things are ever that influential
@mobileink how many languages do you have to support currently?
@bfabry: completely agree. need to better articulate the clojure v. datascience space, for our situation.
@bfabry not even sure. unique situation. i know we do a bunch of java stuff, data scientists do lots of python. some javascript - one of our guys has glommed onto red-node which also worries me. ;)
Also you can send coworkers http://wiki.c2.com/?BlubParadox
@mobileink "maybe a newbie channel would be useful?” — you mean like #beginners ?
i'm leaning toward "boss, let's sponsor some lunches/happy hours for geekiness, and we'll plant some clj evangelists" v. "boss, make them do clj!"
@seancorfield ha! missed that, thanks!
Very helpful crowd hangs out in #beginners — along with lots of brand-new-to-Clojure folks 🙂