This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-18
Channels
- # aws (1)
- # aws-lambda (1)
- # beginners (48)
- # boot (15)
- # cider (3)
- # cljs-dev (4)
- # cljsrn (4)
- # clojure (241)
- # clojure-chicago (1)
- # clojure-dusseldorf (12)
- # clojure-greece (41)
- # clojure-italy (3)
- # clojure-russia (16)
- # clojure-spec (7)
- # clojure-uk (34)
- # clojurescript (88)
- # community-development (9)
- # cursive (8)
- # data-science (55)
- # datomic (40)
- # devops (1)
- # emacs (20)
- # fulcro (19)
- # graphql (3)
- # hoplon (46)
- # luminus (11)
- # lumo (4)
- # off-topic (27)
- # onyx (26)
- # other-languages (25)
- # pedestal (2)
- # powderkeg (6)
- # re-frame (11)
- # reagent (4)
- # ring-swagger (17)
- # rum (4)
- # shadow-cljs (103)
- # spacemacs (14)
- # specter (6)
- # unrepl (21)
- # yada (1)
@noisesmith , @bronsa: thanks for clarifying this, I misunderstood my compiler error
so I'm calling scala from clojure, and I have a functino clj-seq->scala-seq ... and this scala function expects a scala-seq-of-ints and I'm passing it a scala-seq-of-longs (since clojure integers default to longs)
I have a hashmap {:a 1 :b 2 :c 3}
and a vector with a new key order [:b :a :c]
how do I reorder the hashmap?
but if you have a vector of keys then you have an ordering so you could (map #(get collection %) [:b :a :c])
to get a lazy seq of them in the order you gave
hmmm maybe i’ll have to rethink this a bit
yeah this is probably a situation where you can change the data structure a stack frame or two higher
well the hashmap comes from the db
and generates a form, but the elements are in a different order each time
i’d like to force the order
not sure what your db is but rows and columns are not considered ordered in theory despite what may happen in practice
right, thats why I thought there would be an easy way to reorder the hashmap
that puts you right back at my earlier suggestion. you don't care about the order of the hashmap but the order you access the values in the hashmap
right, ok makes sense
I realize this is terrible and never should be done, but I have good reason to do this. Is there a way, from Clojure, to call a private static function of a scala class ? I realize calling private functions is bad -- but in this case, I'm wrapping an API in a clojure-ic manner, and I really need to call this particular private function.
There is only one particular private function I need. so I'm willing to do an expensive reflection of sorts upfront to grab this function.
@qqq I've never tried that with a scala class... but, long as a SecurityManager isn't present, you may be able to use reflection to get ahold of the Method, and modify it's accessibility (via java.lang.reflect.AccessibleObject#setAccessible
)
Probably something like (-> (.getMethod TheClass "theFnName" ...) (.setAccessible true) (.invoke nil args))
but specifying the parameter types to getMethod. You could also use getMethods
and then filter to the one you want, if there's some problem specifying the parameter types.
@rwilson: interesting, I didn't know that one could change accessibility at runtime (I thought maybe private functions were hidden, and there was a way to reference them, but not that one could actually toggle the accessibility bit)
When using clojure.core.server/repl
, is there an easy way to get a client that has backspace support, up-arrow for history, ctrl-c basic functionality?
where this really would break down is for stuff scala doesn't reify into the running code (it just uses the type system to establish what's what and puts an undocumented / non-self-describing structure into the class file)
I'm not certain it does that, but I heard a rumor some things were like this
@eriktjacobsen there's a CLI program called rlwrap that you can wrap around your telnet process talking to the socket repl
other than that, you just want an nrepl client, and to use nrepl in your code
@eriktjacobsen also worth checking out unravel: https://github.com/pesterhazy/unravel
but even rlwrap nc
will be a-ok
what's the best lib for exporting clojure test output, there is to say, I'm testing someting that has many failed assertions, instead of getting number of fails, I'd like to get some sort of checklist, name of the test, maybe the text from the "testing" macro, in nicely formatted text document.
Hi guys, Ive got a general question about Clojure... Ive got a bit of experience with Clojure, and love it, and Ive touched on Haskell. I was thinking of learning Haskell properly, but what do you Clojureists think of Haskell?
I also have the same doubts constantly 😛 Clojure is awesome and probably the best experience I've had developing, but I often miss types. But I don't agree with people who minimize what benefits types bring... The mistakes caught by type systems aren't always trivial to prevent/find; maybe if you have a lot of experience with the language, a very nicely crafted code with the correct abstractions. But that's not always the case. And preventing those kind of errors is only one part of what type systems bring.
I see Clojure and Haskell as both valid but very different approaches to similar problems. My recommendation would be to learn both and then use the one that best fits the problem you’re working on and the “style” you’re most comfortable with.
what I described is exacly here, I should be more thorough with my friend google before asking here. https://github.com/pjstadig/humane-test-output
@daedelus1982 don't need a huge type system when your code is simple and readable
@lsenjov Very good point. Some on the web dislike the dynamic typing of Clojure but this is a excellent counter argument.
i would like static checking @daedelus1982 - i currently have a lang-crush on https://github.com/LuxLang/lux
@mccraigmccraig Actually looks nice, ahhh, so many languages to learn, so little time.
I'm reading some code which seems to be using when
where cond
would do - I thought when
was for side-effects, am I missing something ?
hmm I don't like using if
with only 1 branch
cond
is for that
Coming from common lisp, i'd use if
, but there is another level of parenthesis in common lisp's cond - (cond (1 2))
, so perhaps I'm biased towards using if
including one branch right ?
say you had 2 branches - if
or cond
?
but what are the trade-offs besides style ?
and what about when
vs cond
or if
? when
is only for side-effects right ?
thought so
eh maybe if
with one branch isn't so bad...but whenever I read if
I expect 2 branches
using cond
seems to signal "this is not a standard 2-branch if
"
which helps me scan for single-branches
people sometimes use when
even when side-effects are not used, to avoid single-branched ifs
i'd prefer not to use when
in non-side-effecty cases, because it signals "side-effect here"
not really, some people use it for that but (when foo bar)
is a perfectably acceptable alternative to (if foo bar)
or (if foo bar nil)
only insofaras it works
the docstring never argues that when
should be used in side-effecty behaviour, some people have randomly decided that that's what its only use-case should be
well they're wrong.
Yeah, by 'useful for side effects', really I was saying it doesn't give you any more semantic power
wouldn't there be a small cost in speed ? (because of the implict do
) ?
right
ok the results are in:
(use 'criterium.core)
=> nil
(quick-bench (cond (== 1 2) 3))
Evaluation count : 194420304 in 6 samples of 32403384 calls.
Execution time mean : 1.151155 ns
Execution time std-deviation : 0.094268 ns
Execution time lower quantile : 1.026327 ns ( 2.5%)
Execution time upper quantile : 1.260197 ns (97.5%)
Overhead used : 2.091214 ns
=> nil
(quick-bench (when (== 1 2) 3))
Evaluation count : 93839238 in 6 samples of 15639873 calls.
Execution time mean : 4.354806 ns
Execution time std-deviation : 0.199131 ns
Execution time lower quantile : 4.087070 ns ( 2.5%)
Execution time upper quantile : 4.584328 ns (97.5%)
Overhead used : 2.091214 ns
=> nil
(quick-bench (if (== 1 2) 3))
Evaluation count : 94100316 in 6 samples of 15683386 calls.
Execution time mean : 4.421143 ns
Execution time std-deviation : 0.387452 ns
Execution time lower quantile : 4.082193 ns ( 2.5%)
Execution time upper quantile : 5.040878 ns (97.5%)
Overhead used : 2.091214 ns
probably...trying bench...
ok yep same code
https://github.com/apache/incubator-mxnet/blob/0.11.0/scala-package/core/src/main/scala/ml/dmlc/mxnet/Context.scala#L51 <== how do I convert this from Scala to Clojure ?
if it's just a regular new Context(..).withScope(..)
then just do that in clojure (.withScope body myContext)
so when I try:
(let [ctx (Context/gpu 0)]
(. ctx withScope
(fn []
20)))
I get this error:1. Unhandled java.lang.ClassCastException server.snip.mxnet$eval7691$fn__7692 cannot be cast to scala.Function0
or you can try using https://github.com/t6/from-scala, first google result for scala clojure interop
;)
@bronsa: I'm aware of that project, but have been trying to bind this library 'from scratch' to understand what's going on.
there's no magic solution, clojure and scala use different interfaces to represent their functions, you need to convert one to the other if you want to interop
@bronsa: yeah, https://github.com/t6/from-scala/blob/master/src/t6/from_scala/internal.clj#L369-L400 appears to be what I need
@bronsa: thanks for the tip
(let [ctx (Context/gpu 0)]
(. ctx withScope
(reify scala.Function0
(apply [this]
20))))
appears to have workedI’m trying to use tools.analyzer.jvm to analyze+eval
each form in a seq of forms that I read with tools.reader/read
and I get a FileNotFoundException
because, I think, the ns
macro is one of those forms and it’s requiring another namespace. If I switch to analyze
instead of +eval then I get a no such namespace
error I think because the ns aliases don’t exist since there was no eval. All I want is to parse the analyzed forms and pull out some :binding keys. Anyone know what I’m missing?
@ccann hi, your analysis of the problem is correct, why aren't your ns dependencies on the classpath?
and testing it in my repl, so I’m wondering, if I run this lein <my plugin>
on the project then the classpath with have the deps loaded right?
plugins run in the lein jvm, not the project jvm(they will sometimes inject things in to the project jvm)
I received this comment today [code is not idiomatic because] it's using when for the return value instead of side-effects.
Is it a faux-pas to use when
for the return value? I used it to replace a single-branch if
@dpsutton what a coincidence, I wonder if my feedback was inspired by that conversation 🙂
@acron one thing to note is that there are plenty of places in clojure.core that use when
that way, e.g.:
(defn not-empty
"If coll is empty, returns nil, else coll"
{:added "1.0"
:static true}
[coll] (when (seq coll) coll))
though, naturally, it's simply a matter of preferencethere is apparently history to when
usage coming from the lisp world too, which is at least worth considering: https://lobste.rs/s/aqzj0f/robust_clojure_best_way_handle_nil#c_qejrpi
I always find it hard to navigate this stuff in Clojure, as many users are not coming from the lisp world, and Clojure itself is a mix of lisp and other languages in terms of influences
I've never heard of decisions around when
being tied to side-effects. @dominicm can you elaborate?
@seancorfield I hadn't until just now in the above github pull request
@seancorfield @ddellacosta linked to https://lobste.rs/s/aqzj0f/robust_clojure_best_way_handle_nil#c_qejrpi which seems to suggest it's idiomatic lisp
I do it. But some people advocate that it isn't. I think they're wrong, clojure.core uses this style.
reading
this common-lisp guy one time said on mailing list that when is for side-effects, and some clojure people thought it made sense (because of the implicit do in a when) and have been pushing it ever since
yeah to be clear, I wasn’t trying to suggest any one thing is correct--I just thought it was a relevant bit of historical data. Personally I don’t think of when
in this way, generally speaking.
its why lein has code like https://github.com/technomancy/leiningen/blob/52980074e8476725c97c5bea4e7f1c59c78ce147/src/leiningen/repl.clj#L36
yeah, in fact he was the one that brought it up in that thread--I just found the second explanation more clear
I'm fairly sure at least one of the linting tools complains about single branch if
and suggests when
.
(I thought it was Eastwood but I don't see it documented)
I think it’s kibit or bikeshed that does that
@seancorfield kibit I think
I had a pr on bbatsov's style guide several years ago to delete the whole thing and replace it with a bruce lee quote
@octo221 Tell that to Rich: https://github.com/clojure/clojure/commit/95e04a8d55631a9e83f44f94a95a2ed527741faa#diff-ab81158458e8756a4dd92527cef9e9ecR348
The perfect appeal-to-authority 🙂
perhaps proof that even logical fallacies aren't always to be avoided?
ok I'm convinced!
well not really
i still don't see the point of using an implicit do
if it's not needed
Literal same thing happened w/ my coworker. He let it go, but maintains single branch if
is better.
even if it costs nothing and compiles to the same as if
or cond
personally I dislike the dogmatic nature of "X should only be used for Y"
For me, it's about readability it's hard to hunt down the other expr in a single-legged if
I agree @tbaldridge.
Code reading for me is a pattern matching thing. It's easier for me to match on when
and know it returns a nil or a value. Vs a if
which involves hunting down both legs of the branch to figure out what each one does. If I can't find the second leg, am I missing it? or does it not exist?
It's all a bit of a ridiculous argument since you can have (if some-expr (run-process a) (run-process b))
where run-process
both has side effects and returns a value 🙂
(consider clojure.java.jdbc/insert!
which is very side-effect-y and returns useful information)
when I see if
i expect to see 2 branches too
if there's one i get worried the other one was left out by mistake
So, for me, because "side effects" is a red herring, I expect two branches for if
, one branch for when
(and it signals clearly that I can get nil
back) and for cond
I expect more than two branches.
Besides, in real-world code you're also going to see stuff like (if some-expr (do (side-effect-y a) (compute b)) (compute c))
-- again, the presence or absence of side-effects is a red herring here.
I propose a new conditional (name to be suggested) that's like when
but without the implicit do
but why? @octo221 it's exactly the same thing
@tbaldridge (joke!) - I'm persuaded
3 ways to say the same thing
and no shades of meaning at all ?
With all the talk of AI/ML/TensorFlow/DeepLearning going on at Clojure/conj and the general observation that Python is ahead of the pack in terms of existing efforts, I was wondering if one approach that might leverage those efforts would be a Clojure hosted on Python. I see that @tbaldridge has done some efforts with https://github.com/halgari/clojure-py-redux and https://github.com/halgari/clj-pypy. What kind of effort would it take to get either of those (or a newer, better solution) rolling again or anew? I'd potentially be interested in taking it on depending on some of the factors (is there an interest, what woluld it take to get there, etc.).
Just exploring the idea for now, but wanting to get some thoughts from the experts.
@markbastian I heard a lot of talk about clj/python interop via different mechanisms, but this one is new to me. Mind blown.
@markbastian for what it’s worth both of those were superseded by pixie, which is no longer in active development - the second, like pixie, can’t use python directly, it only bootstraps via python’s vm generator
for using python in a clojure like language, the most mature and featureful thing is likely hy https://github.com/hylang/hy
it’s also the only active one I know of
I'll have to check those out.
It seemed like there were some bring "Python Libraries to Clojure" thoughts in the conj talks (just from what I saw on the videos - Sadly, I wasn't able to attend) and I was just speculating to myself whether it'd be easier to do that or bring Clojure to Python.
Hy is the way to go for now, but it's mostly sexprs for Python.
I'm currently working on reviving Clojure-py, but it's quite a few months out, and will be only from Python(and PyPy) 3. Supporting Python2 these days is just too much work.
Hy even has mutable closures like Python, which is a bit icky, but it may work for awhile.
There was mention of Grawl(?) at Conj as a possible way to run Clojure and Python in the same VM -- any experience reports on that?
That's a bit different, they're compiling the C VM to Java and then running that via Graal, it would work about as well as someone would expect (which is mostly, kindof, not really)
Would have the same problems as PyPy: a lot of python libs depend on both reference counting and memory layouts of Python objects. PyPy breaks both of those, and Graal would probably break at least one.
Yeah, that was what I was referring to when I was thinking "bringing Python to us," just couldn't remember the name.
I would love to be able to somehow magically get to CPython stuff from Clojure, geospatial stuff that wouldn’t work in PyPy. But that seems quite difficult.
Searching for graal python
is not very helpful 😆
It’s a general problem well beyond just TensorFlow. I’m sure there’s other cool Python stuff that would be awesome to somehow squish into Clojure.
@gigasquid has had some discussions with them, it seems the python interop stuff is yet to be fully designed
and sadly that's what kills most alternative python VMs
Oracle's page say they have Python running on Graal but I couldn't find any links to it publicly -- so maybe "running" is subjective at this point. On the subject of Tensorflow, I haven't yet watched the Conj video (which I assume will link to Guildsman) but a quick search did not find Guildsman so if someone has a link, that would save me a bit of time 🙂
Thanks Bill... I have absolutely no idea why I couldn't find it! I swear I even looked at your GitHub account. Must have needed more coffee!
@seancorfield It definitely isn't showing up on google (yet?)
So the better view, IMO, is to bring Clojure to Python which is rather easier considering clojure is designed to be hosted from the start.
@tbaldridge would that just mean reviving your previous work linked above?
more like rewriting, but yes 🙂
@seancorfield Let me know if you have any questions. We've (not many of us) have been hanging out in #tensorflow
and making that work well involves working with Cython. that' part has recently gotten much nicer due to Cython adding support for Python type hinting.
@tbaldridge why cython?
There are some performance critical bits in Clojure. Collections, protocols to name a few. What are the other options besides Cython or mandating PyPy?
@tbaldridge I don't know much about that aspect of python (implementations and differences). I was just wondering.
@seancorfield the python stuff is included with the Graal OTN download, if I remember correctly. That's how the TruffleJS is/was
@tbaldridge - Is there an existing JIRA/task list/etc. you have for the clojure-py-redux-redux effort? Or are you thinking of diving in yourself before soliciting help from the community at large?
I'll move this to #other-languages after this, but it's mostly the latter. There's a lot of foundational interop stuff I want to get done first before looking for porting help
Bit late to the if/when debate, but there is also https://github.com/jonase/kibit/issues/2