This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-17
Channels
- # beginners (45)
- # boot (33)
- # chestnut (9)
- # cider (2)
- # cljs-dev (24)
- # cljsrn (1)
- # clojure (114)
- # clojure-conj (3)
- # clojure-dev (3)
- # clojure-dusseldorf (3)
- # clojure-greece (5)
- # clojure-italy (22)
- # clojure-russia (10)
- # clojure-spec (12)
- # clojure-uk (19)
- # clojurescript (117)
- # core-async (16)
- # cursive (3)
- # data-science (1)
- # datomic (5)
- # docs (13)
- # emacs (1)
- # fulcro (13)
- # graphql (1)
- # hoplon (20)
- # immutant (3)
- # jobs (1)
- # juxt (12)
- # lein-figwheel (1)
- # luminus (4)
- # off-topic (12)
- # onyx (61)
- # portkey (1)
- # re-frame (21)
- # reagent (26)
- # ring-swagger (38)
- # rum (1)
- # shadow-cljs (222)
- # slack-help (4)
- # spacemacs (11)
- # specter (67)
- # uncomplicate (236)
Is there a way to get basic autocompletion without nrepl using just rlwrap java -cp ~/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar:src clojure.main
. Any lightweight jars I can load to get the feature instead using lein repl
?
@xtreak29 I'm afraid there's no easy way. At least no one I'm aware of.
I use lein repl
(mostly with Cider) most of the time and pure clojure repl only very occasionally
I too use Cider and Emacs. However since I am from Python background I got used to starting and closing REPL instantly to start from a clean scratch of the state and deps. Sure I can connect to the REPL using the port but I was just curious about some other lightweight workflow.
If you want to get rid of dependencies from your profiles.clj, you can use lein with-profile base repl
(sorry I thought that but that's probably not how this works - need to dig a bit deeper...)
so yes and no: I still have a couple of dependencies defined in :repl
profile in ~/.lein/profiles.clj and these are loaded. However, the :user
profile should be ignored.
Is datomic.client is just an async counterpart of datomic.api ?
@boldaslove156 datomic.client is for "Clients" and datomic.api for "Peers" (at least that's my understanding) see * http://docs.datomic.com/clients-and-peers.html * http://docs.datomic.com/project-setup.html * http://docs.datomic.com/getting-started/connect-to-a-database.html * http://docs.datomic.com/peer-getting-started.html However, better to ask in #datomic
Thanks!
@jumar I don't see it much of a problem except that I was thinking if I was missing some lightweight REPL. Thanks for the info about deps and profiles.
I'm just wondering why StackWalker
class cannot be found but java.lang.StackWalker
can:
user=> (StackWalker/getInstance)
CompilerException java.lang.RuntimeException: No such namespace: StackWalker, compiling:(NO_SOURCE_PATH:1:1)
user=> (java.lang.StackWalker/getInstance)
#object[java.lang.StackWalker 0x28cb9120 "java.lang.StackWalker@28cb9120"]
DEFAULT_IMPORTS https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L39
@U054W022G great, thanks!
Hey Guys, I’ve open sourced Clojurecademy 🎉🎉🎉 https://github.com/clojurecademy/clojurecademy
is there a way to tell java "just use all the resources on the machine; it's all yours" ?
just run java
boot is hanging on: Retrieving scala-xml_2.11-1.0.4.jar from https://repo1.maven.org/maven2/ (633k)
how long can processing scala-xml.jar take? [I'm calling a scala lib from clojure, so it's apparently pulling in the entire scala compiler chain]
well, anyway getting 0.5mb file should not take long on most networks
so I nuked ~/.m2 ; then I ran boot, and boot has spent 9 minutes pullingin all the jar dependencies so far
it's pulled in much larger ones with no problem:
k)
Retrieving scala-library-2.11.8.jar from (5610k)
Retrieving scala-reflect-2.11.8.jar from (4467k)
Retrieving log4j-1.2.17.jar from (478k)
Retrieving slf4j-api-1.7.5.jar from (25k)
Retrieving slf4j-log4j12-1.7.7.jar from (9k)
Retrieving args4j-2.0.29.jar from (83k)
Retrieving scala-parser-combinators_2.11-1.0.4.jar from (414k)
Retrieving scala-compiler-2.11.8.jar from (15124k)
Retrieving scala-xml_2.11-1.0.4.jar from (633k)
https://clojurians.slack.com/archives/C03S1KBA2/p1508226390000134 I use a bare non-lein non-boot REPL. To be honest I haven't missed autocomplete as much as I thought I would
hi, I'm trying to use clojure to create a Burp extension, basically a jar with a java class burp.BurpExtender that implements some interface
however, when it clojure calls the init method, it throws a notfound exception for clojure/core.clj
there is also another class that defines a main function and that runs fine when called with java -jar X
@qqq it was recently implemented: https://dev.clojure.org/jira/browse/CLJ-1454
@metametadata: awesome! I get to delete
(defn swapr! [atm f]
(let [ans (atom nil)]
(swap! atm
(fn [old]
(swap! ans (fn [_] old))
(f old)))
@ans))
Probably a good idea, that code has a bug anyways 😛
oh wait...maybe not, I didn't notice the double swap
But yeah, read up on https://clojuredocs.org/clojure.core/compare-and-set! it'd make that function a lot cleaner.
bleh need the ! at the end of that url, just google for comapre-and-set!
@U07TDTQNL: iirc, months ago, we had this same discussion over this same problem; I'd like to think my complaints made an epsilon push towards this being implemented 🙂
I have a function with an overloaded parameter say (defn f1 [foo bar-dt] ...) where bar-dt can be either a clj.DateTime or a java.util.Date. So I have an if statement in the function which converts the Date to a clj.DateTime. Switching on a type like this feels wrong (oop leftovers I guess). And a multimethod is too heavyweight for this kind of thing IMHO. Is there some better way to handle this type of overloading?
@dealy you can use a protocol. Something like:
(defprotocol ILikeDates
(f1 [this foo]))
(extend-protocol
clj.DateTime
(f1 [this foo] this)
java.util.Date
(f1 [this foo] (.toCljDate this)))
You could also piggypack on the new Inst
protocol
Are there any Twitch streamers out there that broadcast them working on Clojure related things? Channel links?
That's the idea with #mob-programming although not necessarily via twitch. It's been kinda quiet lately, but we did get a couple sessions going about two weeks back. (Using twitch and teamspeak)
can someone tell me how to read a clojure source file without evaluating it? I just want to parse it as clojure data structures and manipulate those.
since edn is a subset of clojure, do I have to use read
? read
seems to want to validate that the symbols in the file I’m reading are resolvable (which they aren’t) EDIT: read
is not validating symbols, I was incorrect
you can also use the org.clojure/tools.reader project, which gives you a few more knobs @ccann
I have some name spaces that I'd like to extract (along with tests and dependencies) into their own repo my env is cider and emacs are there any tools in there to make this quick'n'painless?
@josh.freckleton clj-refactor.el might help https://github.com/clojure-emacs/clj-refactor.el/wiki
checking it out now thanks
in clojure, when I have a function like (let [a [1 2 3]] (fn [x] (contains? (set a) x))
, will the function create the set at every invocation, or is this optimized?
I don’t think it can be - since clojure doesn’t exiplicitly track side effects so can’t prove set isn’t doing something useful on each run
would the jvm jit do something like that after a while? my fundamental jvm knowledge is lacking
I almost suggested changing set to println to see if it gets optimized, but I think we both know what it would do 😄
right, the easy workaround there is to move the set call into the let block (but of course real code might be trickier)
so even if it was (fn [x] (let [a [1 2 3]] (contains (set a) x))
? I assumed it would only be made once because of the closure
@dpsutton but clojure doesn’t know that set is without side effects as far as I know
if it would break if that was a println call, I don’t think clojure can automatically hoist it
"collections that only have constants are hoisted". his example had the collection defined outside the fn body so it was already hoisted. I was asking if it was defined inside of the function body would it still only be created once
constant expressions are generally hoisted and created once statically, whether the expression is scalar or a collection
Way to prove this:
(let [a (transient [1 2 3])
my-fn (fn [x] (contains? (set (persistent! a)) x))]
(println (my-fn 5))
(conj! a 5)
(println (my-fn 5)))
The 2nd my-fn throws an error IllegalAccessError Transient used after persistent! call clojure.lang.PersistentVector$TransientVector.ensureEditable (PersistentVector.java:548)
(there's probably a better way to prove that the (set (persistent! ...))
runs, and it's not apples to apples, but it kind of proves the point)
yeah, that looks like empirical proof that the optimization doesn’t happen, (though you are right @dpsutton that a clever compiler probably could do that)
and if it were a clever compiler, it would realize not to do it in the case there's a known side effect, like what I introduced there....
then again, set is a var, so to be fully consistent we can’t make assumptions about its redefinition without opting in…
it would be dumb to redefine clojure.core/set at runtime, but the language says its allowed
@tanzoniteblack aside: make sure you use the result of (conj!...)
in this case, we don't really need to. conj!
, while returning the original coll, also works just as a side effect.
(let [coll (transient [])]
(run! #(conj! coll %) (range 5))
(persistent! coll))
;; [0 1 2 3 4]
i.e. don't use transients in your code unless you know what you're doing and really need to 🙂
conj! is not valid if you call it on the same collection over and over. and your simple example will not reveal the bug I'm referring to. need to call conj! on the result of calling conj!
I think you might be confusing conj
and conj!
? Or, if I'm wrong on that, can you please provide an example where the bug you're talking to comes into play?
cool, thanks. I do seem to have had that wrong
n.p. -- i forget where exactly the change happens, it's not at 32 elements because I just tried that
@borkdude the Clojure compile does very few optimizations, I see this as somewhat of a good thing. It's easier to predict performance when there's fewer optimizations, but this set example is one I've seen quite a few times.
(contains? (set a)) is going to be slow-ish depending on the size of a
. But for smaller sets, it may not matter
And performance wise, there's little difference between (filter #{a b} coll)
and (filter #(or (= % a) (= % b)) coll)
haha, I was frowned upon once when I used that idiom of set contains in Scala, because I didn’t want to type my ||
expressions out, was so used to doing this in Clojure
https://clojurians.slack.com/archives/C03S1KBA2/p1508272917000202 if the sets are constant it doesn't matter
how do I test is a number is a java long ? (some java functions want java ints, and I need to coerce longs to ints)
@qqq can always check the class: (instance? Long x)
@qqq I was under the impression that when clojure sees that a method takes int, it accepts a long and implicitly converts - is that not working?
that is correct @noisesmith, unless the method also has a long overload and he explicitely wants the int one
ahh, that would be a gotcha
but also a rare case
but even then you wouldn’t need to check for longs, you can explicitly call int