This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-20
Channels
- # bangalore-clj (1)
- # beginners (145)
- # boot (8)
- # braid-chat (2)
- # capetown (2)
- # cider (27)
- # cljs-dev (232)
- # cljsrn (30)
- # clojure (223)
- # clojure-boston (1)
- # clojure-dusseldorf (2)
- # clojure-greece (1)
- # clojure-italy (21)
- # clojure-russia (16)
- # clojure-sanfrancisco (13)
- # clojure-spec (33)
- # clojure-uk (56)
- # clojurescript (165)
- # core-async (16)
- # core-logic (5)
- # cursive (14)
- # data-science (2)
- # datavis (2)
- # datomic (49)
- # duct (15)
- # editors (5)
- # emacs (6)
- # fulcro (11)
- # graphql (11)
- # hoplon (8)
- # jobs (4)
- # jobs-discuss (82)
- # jobs-rus (7)
- # leiningen (4)
- # luminus (5)
- # off-topic (90)
- # om (7)
- # om-next (1)
- # parinfer (67)
- # pedestal (34)
- # portkey (46)
- # re-frame (12)
- # reagent (4)
- # reitit (3)
- # remote-jobs (1)
- # ring-swagger (8)
- # shadow-cljs (13)
- # spacemacs (18)
- # specter (6)
- # sql (5)
- # tools-deps (4)
- # unrepl (40)
- # yada (26)
@qqq here is the long explanation: http://cr.openjdk.java.net/~jrose/values/shady-values.html
@pablore no, it is sort of like a struct in C, less indirection and higher performance than objects for certain use-cases
Is https://stackoverflow.com/questions/3132931/mutable-fields-in-clojure-deftype up to date? To make a field mutable, I need to mark it volatile
@ghadi well clojure’s data structures are not only inmutable, they are also persistent. And because of that I find it difficult to implement them with these new “values”.
I seem to be loosing the :p
argument somewhere along the way here:
(defprotocol F
(-f [this a & r]))
(defn f [this a & r]
(prn [:f {:this this :a a :r r}])
(apply -f this a r))
(defrecord Fer []
F
(-f [this a & r]
(prn [:-f {:this this :a a :r r}])
{:a a :r r}))
(def fer (->Fer))
(f fer :x :p {:args :foo})
;; => {:a :x, :r {:args :foo}}
;; stdout
;; {:this #user.Fer{}, :a :x, :r (:p {:args :foo})}
;; {:this #user.Fer{}, :a :x, :r {:args :foo}}
Looks like it's happening when the f
wrapper function calls the -f
protocol method implementation. Any ideas what's going on?
Compare with using only functions: :p
isn't lost:
(defn -g [this a & r]
(prn [:-g {:this this :a a :r r}])
{:a a :r r})
(defn g [this a & r]
(prn [:g {:this this :a a :r r}])
(apply -g this a r))
(g :this :x :p {:args :foo})
;; => {:a :x, :r (:p {:args :foo})}
;; stdout
;; [:g {:this :this, :a :x, :r (:p {:args :foo})}]
;; [:-g {:this :this, :a :x, :r (:p {:args :foo})}]
you've accidentally defined a protocol that takes three arguments -- one of them is named &
- if you printed &
within the protocol implementation, you'll find your missing argument
i think that's one of the differences in clj/cljs. because of the host language cljs
yes, left to right : https://clojure.org/reference/evaluation
Does lein not inject :test
dependencies when you run a REPL? I thought it did, but I’m not able to explain how looking at the implementation of the repl
task and my project’s profiles via show-profiles
.
I don't think running repl task will inject :test
dependencies as I can see from the below. I might be wrong though . Maybe you can try lein with-profile test,repl repl
(Not verified)
> Some tasks automatically merge a profile if specified. Examples of these are the :test profile, when running the test task, and the :repl profile, when running the repl task. Please note that putting things in the :test profile is strongly advised against as it can result in tests which can't be run from the repl.
https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md#task-specific-profiles
How is Clojure tested with JDK 10 which is on release candidate phase ? I can see reports of the Kotlin compiler breaking on JDK 10 early access releases : https://github.com/junit-team/junit5/issues/1169
Seems like there is a test case failing. Filed : https://dev.clojure.org/jira/browse/CLJ-2337
fyi, this is just a fragile test, not an issue with Clojure and Java 10
@xtreak29 it’s already been reported as https://dev.clojure.org/jira/browse/CLJ-2330
@bronsa Thanks. My bad "JDK 10" didn't bring up any tickets in JIRA search. I will close it then.
When a macro contains ~*ns*
, does it imply that we are forcing it to evaluate at that point of time?
I think you are right but I am curious if there are any exceptions
$ clj
user=> (defmacro foo [f & rest] `(str ~*ns*))
#'user/foo
user=> (foo 1)
"user"
user=> (ns spam)
nil
spam=> (user/foo 2)
"spam"
I found its usage in clojure/tools.loogging
and want to understand what are its cost implications
here's a related SO question: https://stackoverflow.com/questions/9678425/namespace-confusion-and-macros
Seems like a nice way to print the current namespace useful for logging. I also found a similar quoted usage in core : https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L1828
if clojure.java.jdbc seems bloated (I don’t think it is), then java interop is reasonably easy way to do it
I followed some of its design for another lib I authored, so I am quite familiar with it too
squee seems quite nice/simple, clojure.java.jdbc seems like an obvious contender but it seems a bit bloated at first glance, maybe it doesn't matter
(Shameless plug) I wrote Asphalt https://github.com/kumarshantanu/asphalt to use SQL “in anger”. We are using it at Concur in production for over two years with MySQL and MS-SQL. Has no dependency.
@mpenet You might get more responses on the #sql channel.
Has anyone seen similar exception to this? ERROR [compojure.api.exception:286] - clojure.pprint.proxy$java.io.Writer$IDeref$PrettyFlush$4923d848 cannot be cast to clojure.pprint.PrettyFlush
Application is packaged as uberjar (tried both {:aot all}
and only namespace with main), it works normally on localhost however it produces errors like this on AWS. Application works correctly, however it replaces original expcetion with this one on error. I tried to remove various dependencies and played with AoT but nothing so far helped 😕
Googled the error : https://github.com/cursive-ide/gradle-clojure/issues/7 Try removing pprint ? (https://clojurians-log.clojureverse.org/clojure/2015-11-21.html#inst-2015-11-21T18:42:03.001467Z)
I have read it however dropping to 1.7 doesn't sound like a good option 🙂
@petr.mensik any particular reason why you're AOT'ing? That can lead to all sorts of trouble
@pesterhazy I ended up with :profiles {:uberjar {:aot [spc.core]}
which is default - I thought that namespace containing the -main
has to be AoTed
yeah right
another thing you can try is java -cp uberjar.jar clojure.main -e '(do (require 'myproj.main) ((resolve 'myproj.main/-main'))'
I think that should work right?
in which case you shouldn't have to AOT anything
Ok, I can try that, thanks
updated the snippet ^^ let me know if it works
And how do I workaround the fact that lein uberjar
adds implicit AoT for the :main?
Warning: specified :main without including it in :aot.
Implicit AOT of :main will be removed in Leiningen 3.0.0.
If you only need AOT for your uberjar, consider adding :aot :all into your
:uberjar profile instead.
Compiling spc.core
@pesterhazy Ok, I removed the :main
from project.clj and I am able to build it. However java -cp mayjar.jar clojure.main -e '(do (require [spc.core]) (resolve 'spc.core/-main'))'
yields a Exception in thread "main" java.lang.ClassNotFoundException: spc.core, compiling:(NO_SOURCE_PATH:1:5)
@petr.mensik there's an apostrophe missing before the ns
`"(do (require 'spc.core) ((resolve 'spc.core/-main)))"
note the doulbe parentheses around resolve
@pesterhazy ok, it works locally so I'll let you know if it works on the AWS as well. However it's still not that nice since I have to change default run command on all instances 😕
But definitely thanks!
agreed. The other way should work as well (only aot a single ns)
Has anyone used an API that consumes com.fasterxml.jackson.databind.JsonNode
s? I’m trying to figure out if an existing clj-library (like cheshire or jsonista) can produce such one from Clojure datastructures.
hello guys, a quick question about classloaders and require
, maybe somebody here played with it: Even though I add a dependency to classpath with pomegrenate, the require
of the dependency still fails... It IS definitely on the classpath of that given classloader. I tried tweaking *use-context-classloader*
but it seems to make no difference. What am I missing? (Tried this so far only in repl, not sure whether that may be relevant?)
(let [new-cl (-> (Thread/currentThread)
(.getContextClassLoader)
(clojure.lang.DynamicClassLoader.))]
(cemerick.pomegranate/add-dependencies :coordinates [['com.draines/postal "2.0.2"]]
:classloader new-cl)
(.setContextClassLoader (Thread/currentThread) new-cl)
(require 'postal.core))
FileNotFoundException Could not locate postal/core__init.class or postal/core.clj on classpath. clojure.lang.RT.load (RT.java:449)
it's possible that clojure doesn't use the context classloader. I'm not certain though. Clojure is a bit funky with classloaders.
I think by default it should be using the context classloader... will try to tag @cemerick, maybe he's around?
ok, after some poking in the RT.class it seems that this really might be REPL related:
public static ClassLoader baseLoader() {
return Compiler.LOADER.isBound()?(ClassLoader)Compiler.LOADER.deref():(booleanCast(USE_CONTEXT_CLASSLOADER.deref())?Thread.currentThread().getContextClassLoader():Compiler.class.getClassLoader());
}
I guess in REPL the loader is bound hence it wont ever check *use-context-classloader*
. So will have to test this in uberjar and to see whether it works...I think by default it should be using the context classloader... will try to tag @cemerick, maybe he's around?
Does anyone have experience using clojure.core/hash as a way to give a unique ID to maps? What are the pros and cons of using that vs something like sha256? I was surprised how few numbers are in the clojure hash and it seems like collisions would be much more likely, no?
My use case is I have a bunch of JSON objects and i want to detect dupes, but avoid false positives
Java hashes are constrained to be 32-bit integers
hash collisions are of course possible (the murmur hash changes in 1.6 have made this less common)
I would not use it as a way to obtain unique IDs (since they aren’t necessarily unique)
well they should probably be the same but would potentially vary across clojure versions.
well, clojure controls the collection hashes and I think the jvm spec controls primitive value hashes so that is probably not the case
@alexmiller would it be inadequate to add the '-m -M .clj' options to rlwrap for the 'clj' script in the repo? those flags fire up your $EDITOR with ctrl-^
did you mean .clj there?
those options don’t work for me on mac at least
I don’t particularly want to lock in too hard to rlwrap as I’m hoping to actually integrate rebel-readline instead
https://github.com/hanslub42/rlwrap rlwrap has some serious options.
@alexmiller what version of rlwrap is on a mac?
depends on whose mac you mean :)
whatever brew installs :)
@alexmiller ok, haven't tried it in a mac, works fine on linux, weird it doesn't work in osx though, didn't know about rebel-readline, fair enough
looks like I have 0.43
@alexmiller me too
rlwrap: warning: on this system, the getopt() library function doesn't
grok optional arguments, so '-M' is taken as an argument to the -m option
Is this what you meant? If not, please provide an argument
so I think that’s about the -m part which expects an argument
@alexmiller would rebel-readline be optional? or at least opt-out, don't want to slow down that start-up time 😉
still needs evaluation. why do you think it’s slower?
I would happily trade a small amount of time for the vastly increased functionality
yes, was just about to say that I don't really know how much overhead it would bring, just that is another dependency (which has its own dependencies, jline) that is needed for boot up
that doesn’t make it any slower necessarily
@alexmiller Try -m' \ ' -M ".clj"
that seems portable
@devicesfor you can try it with clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.1\"}}}" -m rebel-readline.main
yourself (but ignore the first timing as it has to download and cache deps)
note that b/c of how it’s being started there are some inefficiencies that can be reduced - for me I see ~2 seconds to start a repl with clj
and maybe 7 seconds with rebel-readline
consider that an upper bound - if included and packaged with clj, I’m sure this can be reduced
given what rebel-readline gives you (multi-line editing, completion, doc arglist and source inline), it’s pretty useful
@alexmiller I'm sure clojure 1.10 will bring that down too 🙂
oh, there are other ideas in work but I’m not sure they would affect this necessarily
;; lazy, will only traverse once
(def colors ["red" "green" "blue"])
(println
(map #(str % "foo") (map first colors))
;; => ("rfoo" "gfoo" "bfoo")
can someone please help me understand why is this being traversed once?@bravilogy what result do you expect?
@hiredman yes, map
returns a lazy sequence. so when (map first colors)
runs, doesn’t it iterate over colors
vector to generate that lazy sequence?
@bravilogy Creating a lazy sequence from a lazy sequence doesn't require traversal.
https://clojure.org/reference/reader#_symbols is there a reason % is not listed here?
@pauld so the second (outer) map doesn’t actually iterate over the lazy sequence generated by the first one?
@bravilogy it does
@bravilogy there are twoo, inner and outer map
@bravilogy evaluate (map first colors) in your REPL
@bravilogy why do you think there is only one?
because the comment says so @devicesfor
I’m looking at this page basically https://kanaka.github.io/clojurescript/web/synonym.html
@the2bears I think I’m not explaining correctly which part I don’t understand 😄 I know what the result would be and how 2 map
s work but what I don’t get is that the comment in there - why will it only be traversed once
@bravilogy to understand you might have to look at the code of (map) in clojure. But the key is just knowing you can create a lazy sequence from a lazy sequence without realizing / traversing the first one.
map takes an iterator, and returns an iterator that calls the mapped function on each value as you take it from the iterator
sure, but you are generating intermediate seqs as you go, where transducers don't do that
no that’s fine, I think I understand now. so basically that example is sort of similar to
(take 5 (range))
in a sense that the inner map will generate a sequence that will be ‘fed’ to the outer map and that’s what will actually ‘realise’ it
@bravilogy oh I see, yes colors is only iterated once, but your example has two iterations
lazy sequences can sometimes be confusing as you may get surprised by when the sequence is evaluated or realized.
would it be the same result if I was to simply change it to
(def my-seq (map #(str % "-foo") (map first colors)))
(println my-seq)
?@alexmiller seems the -Sdeps
option is quite new? 4.2s for the rebel-readline on my ubuntu box, 4.8s on a fairly recent mbp
@mbjarland The -Sdeps
option came in January with TDEPS-19 Add support for command line deps config data
@seancorfield Is there a way to use TemporalAdjusters with joda.time? I am referring to clj-time
but I cant find functions for dayOfWeekInMonth
and firstInMonth
@vellalpavani You'll have to use Java interop to call those. Not everything in Joda Time is exposed directly in clj-time
.
@seancorfield Thank you. I will use clojure.java-time.
(and, for all sorts of reasons, I'd recommend using Java Time over Joda Time these days -- and looking at clojure.java-time
as a wrapper if you don't like Java interop)
When would it be a good idea to use a StructMap over a Record? The documentation for StructMap says "Most uses of StructMaps would now be better served by records.". What would "most" not cover?
Ah, I didn't see it say that anywhere.
structmaps are mostly about optimizing storage, Records can integrate with protocols, and still have optimized storage
Isn't there an overhead for creating a proper JVM class?
Hello, I am trying to transform a UTC date string into a Local date string: “2018-03-20T12:40:40Z” -> “3/20/18 8:40am”. I’ve tried various to-local-date-time and unparse-local functions, but I can’t seem to put it together. I’m getting an error:
ClassCastException org.joda.time.DateTime cannot be cast to org.joda.time.ReadablePartial clj-time.format/unparse-local-date (format.clj:212)
I got it to: (def local-date (local/to-local-date-time "2018-03-20T12:40:40Z"))
=> #'recruit-app.util.date/local-date
local-date
=> #object[org.joda.time.DateTime 0x311f327a "2018-03-20T08:40:40.000-04:00"]
but then I need a way to reformat it to something readable, (tf/unparse-local-date (tf/formatter :mysql) local-date)
ClassCastException org.joda.time.DateTime cannot be cast to org.joda.time.ReadablePartial clj-time.format/unparse-local-date (format.clj:212)
I'm trying to understand locals clearing, I'm looking at the bytecode for this simple function (m is a Java hash map):
(defn put [m k v]
(.put m k v))
and it has a bunch of this going on:
0 aload_0 [m]
1 aconst_null
2 astore_0 [m]
seems like it's unnecessary to clear locals in this case? when is local clearing needed? is it for recur
?the clearest case for it is holding on to the head of a seq in a binding but passing it in tail position to another function
I saw that thread bronsa but I wasn't sure it was still relevant since it's all the way from 2009
@tlomberg Are you wedded to Joda Time (`clj-time`)? If you're on Java 8 or later, the Joda Time folks recommend using Java Time instead, and there's a nice wrapper called clojure.java-time
.
Here's that parsing / add timezone / formatting using clojure.java-time
:
user=> (require '[java-time :as jt])
nil
user=> (-> (jt/zoned-date-time "2018-03-20T12:40:40Z") (jt/with-zone-same-instant "America/Los_Angeles") (->> (jt/format "MM/dd/yy hh:mma")))
"03/20/18 05:40AM"
there's been a few improvements and it happens in places where it didn't use to but the general principle is the same
@seancorfield: Thanks, I’ll look into it
@bronsa aight, thanks :thumbsup: I guess I want to follow the PathNode
s in the compiler to figure out how it's done?
(FWIW, I'm one of the maintainers of clj-time
and I just updated the repo to include the notice from the Joda Time website that recommends users migrate to JSR-310 a.k.a. Java Time)
or you can look at https://github.com/clojure/tools.emitter.jvm/blob/master/src/main/clojure/clojure/tools/emitter/passes/jvm/clear_locals.clj for an alternate impl
Is there any language with Clojure-like syntax and is good for high performance numerical computing?
i think there’s a lib that can do hardware acceleration and stuff for clojure….trying to remember the name of it
@jgh: it's a wonderful answer to the question I asked, but not the question I intended to ask, as the cuda/opencl 'kernels' are still not written in clojure 🙂