This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-23
Channels
- # announcements (1)
- # babashka (29)
- # beginners (53)
- # berlin (1)
- # cider (14)
- # clj-kondo (18)
- # cljsrn (16)
- # clojure (141)
- # clojure-france (4)
- # clojure-italy (8)
- # clojure-norway (1)
- # clojure-uk (57)
- # core-async (7)
- # cursive (3)
- # data-science (2)
- # datomic (12)
- # duct (5)
- # fulcro (27)
- # hoplon (37)
- # immutant (1)
- # jobs (2)
- # jobs-discuss (7)
- # kaocha (2)
- # leiningen (3)
- # music (17)
- # nyc (1)
- # off-topic (22)
- # pathom (27)
- # re-frame (33)
- # reitit (23)
- # shadow-cljs (20)
- # tools-deps (15)
- # vim (29)
kibit is yelling at me for trying to map over a closure
(defn foo [tag ids]
(map (fn [id] [tag id]) ids))
tells me
Consider using:
tag
instead of:
(fn [id] [tag id])
any idea how could i resolve this without disabling linting?Good morning! All of these solutions are working for me on the REPL, but they're not working on 4clojure. What's wrong?
Ok, sorry guys.. I forgot the exclamanation mark! 🙂
Never mind.
I've written a small clojure interpreter that takes edn code and runs it. Unfortunately I've hit a limitation on .
forms, e.g. .close
. I don't really know how to run such a thing in the JVM? Do I need to use reflection?
@dominicm yes, that would require reflection, here’s where the Clojure compiler handles all that stuff: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Reflector.java
To check, is there no alternative to eval
which can evaluate something like:
user=> (eval `(deref ~(delay 1)))
@dominicm you want to pass in an already evaluated binding to the expression, right?
the way I handle that in sci is:
(sci/eval-string "(deref d)" {:bindings {'d (delay 1)}})
1
Is there an existing library somewhere to transform Swagger models to specs? I see https://github.com/metosin/spec-tools for going spec -> swagger, but I haven't found anything going the other way.
How do I extract "src/clj/collection/sensordata_test.repl" 117
from the ex-info below?
#error{:cause "Transcript assertion failed! -- Spec failed --------------------
true
should satisfy
false?
-------------------------
Detected 1 error
",
:data #:clojure.spec.alpha{:problems [{:path [], :pred clojure.core/false?, :val true, :via [], :in []}],
:spec #function[clojure.core/false?],
:value true},
:via [{:type clojure.lang.ExceptionInfo,
:message "Transcript assertion failed! -- Spec failed --------------------
true
should satisfy
false?
-------------------------
Detected 1 error
",
:data #:clojure.spec.alpha{:problems [{:path [], :pred clojure.core/false?, :val true, :via [], :in []}],
:spec #function[clojure.core/false?],
:value true},
:at [collection.sensordata_test$eval59578
invokeStatic
"src/clj/collection/sensordata_test.repl"
117]}],
:trace [[collection.sensordata_test$eval59578
invokeStatic
"src/clj/collection/sensordata_test.repl"
117]]]}
Did you mean ex-data
? Because that’s:
#:clojure.spec.alpha{:problems [{:path [], :pred clojure.core/false?, :val true, :via [], :in []}],
:spec #function[clojure.core/false?],
:value true}
I’m getting a little thrown by the presentation here. the ExceptionInfo presents like a map but is not one?
ah, you need to use this fancy new fn https://clojuredocs.org/clojure.core/Throwable-%3Emap
Thank you @U050MP39D! That was the fn I could not find 🙂
hmm, 2 recent questions on http://ask.clojure.org are asked by @alexmiller, is this legit or a bug?
op asked 3 questions in one question so I split into 3
i'm looking for library to do haversine distance and handle conversion between units (km, miles, etc.)
im happy to do interop, but also wouldn't mind a clojure-y solution -- i've googled, but am wondering if anyone has a recommendation
i may just go ahead and implement it, but a small lib with some added convenience would be nice
@devn something like this? https://github.com/ThomasMeier/haversine
not sure if this is the appropriate channel, but how do I make a JFrame "visible" to Mac OS? Such that it appears in the Dock / can be switched to via Cmd-Tab
@lukaszkorecki yeah, was looking at that, sort of makes me just want to write the basic formula myself
(defn haversine-distance
[start-lat start-long end-lat end-long]
(let [earth-radius 6372.8
haversin (fn [x] (Math/pow (Math/sin (/ (double x) 2)) 2))
d-lat (Math/toRadians (- end-lat start-lat))
d-long (Math/toRadians (- end-long start-long))
start-lat (Math/toRadians start-lat)
end-lat (Math/toRadians end-lat)
a (+ (haversin d-lat)
(* (Math/cos start-lat)
(Math/cos end-lat)
(haversin d-long)))
c (* 2 (Math/atan2 (Math/sqrt a) (Math/sqrt (- 1 a))))]
(* earth-radius c)))
however, i do wonder down the line if ill run into more of this kind of thing. I saw there's a clojure geo and geo-clj, gonna give those a peek next
Hello,
I am running integrant with a the capability to create processors
. Processors have a handler that subscribes to a redis topic for subscribing and publishing.
Such configuration is done reading a edn file with a vector of maps such as the following
[{:sub :telephone
:handler myapp.processor/telephone
:pub {:channel :fax}}]
anwyay, this work great. However, the processor for telephone call different functions and the function send data to a sse stream.
I run the jar file such as java -jar target/myapp.jar`
and I get an exception such as
Caused by: java.lang.IllegalAccessError: send-data-sse does not exist
More interesting, if a stop the jar file and run it again the exception is gone. IF i repeat the same process, It will be running with exception then without exceptionsounds like the kind of problem you get when using aot / gen-class and then having some part of your app reload the definition in the running process
just a hunch though
the exception message doesn't seem to name the thing from the handler so possibly unrelated
you are some how creating an empty namespace that is supposed to contain send-data-sse, but doesn't, and trying to use send-data-sse then causes that error
the main integrant project doesn't mention processors, and googling didn't turn up any integrant based library with whatever those are, but I am kind of guessing, if your example configuration is just made up data, but the error shown is the real error, that would explain why they don't match, and likely whatever the code is that adds this processor feature it is broken
There is nothing about processors. It was a self implementation. It works great to receive data, processed it, and send it somewhere. one processor handler diverges the data to separate namespaces to process the data differently for an specific output and send that out to another redis channel. the namespaces all of them use sse-send-data and for some reason when the jar file is ran once it runs 100% good. The second or third time, will throw out the exception at the moment the jar file is run for some reason I can't explain
I do this with several micro services using the same integrant boilerplate. Only one service is throwing this out to me.
my guess is your processor code isn't correctly loading the namespace of the handler
and you have some kind of race condition where the namespace may be loaded normally before the process stuff gets to it
in fact, it seems a good bet that the difference between the cases where you get the error and not is based on if there is a message "in the queue", and what is happening is your handler code is being run before the namespace is loaded
e.g. 1st run, there is a message in queue, immediatly grabbed and is attempted to be processed before the namespace with the handler is loader, 2nd run that message has been removed from the queue, so no error
since processors are something you created, I would also strongly suggest that they should be other things in the integrant dependency graph, not functions in a var, so if they depend on anything else in that graph it is captured there. using a function in a var (a global) means if your "processor" needs any other functionality to only way to get it is via a global
Curious how this 4Clojure solution works, it seems that \c
matches \(
and I haven't found any explanation whilst searching
(comp {\# :set \{ :map \[ :vector \c :list} first str)
http://www.4clojure.com/problem/65
The code is a very simple parser that gets the first character of a collection and uses a dictionary (hash-map) to return the relevant keyword.
Is the \c
a peculiarity of 4Clojure and its version of Clojure or some interesting ascii code or character literal? Thanks.why do you think it matches?
I dont think it does, but it passed the 4Clojure tests
afaik, there is nothing special about \c and it should not match \(
one note is that 4clojure runs a very old version of clojure and potentially there is some difference or bug there, don't know
This is my fallback assumption if no one else knows of why this works 🙂
answer: "clojure.lang.LazySeq@db6f4287"
user=> (str (range (rand-int 20)))
"clojure.lang.LazySeq@9ebadac6"
lazy seqs used to toString like that (they now print the sequence) - this changed at some point
that appears to be half right
Clojure 1.10.1
user=> (str (range (rand-int 20)))
"(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)"
user=> (str (map identity (range (rand-int 20))))
"clojure.lang.LazySeq@a0c74788"
maybe it was the range re-impl in 1.7 that changed that
not to distract from the discussion too much but I’m laughing quite a lot at toString’ing the collection as an answer to that problem
:) pr-str
will do what you want here on any version btw
yeah, this was changed in the range re-impl
range is now supported by two (well, actually 3) impls
the 99% case is a range defined only by start/stop/step with longs in LongRange. These are always finite so there is no reason to protect against printing infinite lazy seqs. That's the case above.
other finite ranges are in Range, those will also print all
looks like infinite ranges also try to print as of 1.7, but you will wait a long time for that to fail :)
but perhaps the better lesson is to not ever try to print potentially infinite sequences
I'm not sure I understand the point of that 4clojure question given its restrictions (which excludes all the predicates that you would normally use for this)
well that is a long way to go for that
Thanks for solving this little mystery Alex, much appreciate
i thought the reason was that the JVM didn't support multiple classes with the same name
I think the actual rule is closer to you can only have one class with a given name per classloader, but you can have as many classloaders as you like
Way back, before 1.0, the way clojure namespaces are compiled changed, and before that clojure had a more flexible class generating macro, but that was removed and replaced with gen-class which is more restrictive and tied to aot compilation
@emccue Those are two different A
classes:
user=> (defrecord A [])
user.A
user=> (def a1 (A.))
#'user/a1
user=> (defrecord A [])
user.A
user=> (def a2 (A.))
#'user/a2
user=> (class a1)
user.A
user=> (class a2)
user.A
user=> (= (class a1) (class a2))
false
am not sure, but I believe the difference between records and gen-class there is intended use
because records are primarily intended to be used from clojure, having their behavior match clojure's more dynamic abilities is useful
@seancorfield That makes perfect sense
(gen-class
:name "some.package.Apple")
=> nil
some.package.Apple
Syntax error (ClassNotFoundException) compiling at (form-init15779309300631176008.clj:1:1127).
some.package.Apple
but gen-class is more for interop, for which aot with a stable classloader is better
that argument doesn't make all that much sense to me - a usecase of definterface and co. is already to AOT and use from java as needed
gen-class is explicitly a no-op when not compiling from a file
From the gen-class
docstring: "When not compiling, does nothing."
(gen-interface :name "some.package.Orange")
=> some.package.Orange
(import some.package.Orange)
=> some.package.Orange
triaged means Alex Miller marked it that way, and thinks it is worth Rich considering it for vetting, meaning roughly "interested in a fix"
IIRC a thing that is triaged is put aside for the sake of something more urgent, or placed before something less urgent, and you need more context to know which
it literally means "assigned some degree of urgency"
yeah I was criticising this use of language, not being pedantic
or - not trying to be
scroll down to "Workflow" section
It seems reasonable to use a word like triaged for this, if you think the word has any meaning outside of a medical context at all. The triaged tickets have been examined by one professional (Alex) for their judgement, and put into the bin of "more urgent than the ones not so marked".
the synonym "prioritized" not only shares the meaning, but also is unambigous (and has the here intended meaning) when used generically