This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-18
Channels
- # alda (6)
- # architecture (1)
- # bangalore-clj (3)
- # beginners (39)
- # boot (292)
- # braveandtrue (1)
- # cider (7)
- # clara (2)
- # cljs-dev (20)
- # cljsjs (9)
- # cljsrn (42)
- # clojure (127)
- # clojure-chennai (1)
- # clojure-dev (96)
- # clojure-india (1)
- # clojure-russia (175)
- # clojure-spec (56)
- # clojure-uk (11)
- # clojureindia (1)
- # clojurescript (82)
- # core-async (7)
- # cursive (21)
- # data-science (1)
- # datomic (173)
- # funcool (4)
- # hoplon (8)
- # instaparse (1)
- # jobs (7)
- # jobs-discuss (1)
- # jobs-rus (30)
- # lambdaisland (1)
- # lein-figwheel (8)
- # off-topic (5)
- # om (51)
- # onyx (79)
- # other-languages (7)
- # planck (8)
- # re-frame (95)
- # reagent (6)
- # rum (8)
- # specter (4)
- # untangled (54)
- # yada (5)
(/ 100 0.0)
apparently calls clojure.lang.Numbers.divide(JD)D
, which has no check for zero https://github.com/clojure/clojure/blob/clojure-1.8.0/src/jvm/clojure/lang/Numbers.java#L3803
it sounds like a bug to me
I see
boot.user=> (/ 100 0)
java.lang.ArithmeticException: Divide by zero
boot.user=> (/ 100 0.0)
Infinity
boot.user=> (/ 100.0 0)
Infinity
boot.user=> (/ 100.0 0.0)
Infinity
which seems reasonable to me — floating point divide (the last three cases) by zero produces Infinity
; integer divide (only the first case) produces an exception.(that’s on Clojure 1.9.0 Alpha 10)
the interesting behavior is what happens if you define (def bla 0.0)
and then (/ 100 bla)
Indeed… that is… odd:
boot.user=> (def a 0)
#'boot.user/a
boot.user=> (def b 0.0)
#'boot.user/b
boot.user=> (/ 100 a)
java.lang.ArithmeticException: Divide by zero
boot.user=> (/ 100 b)
java.lang.ArithmeticException: Divide by zero
boot.user=> (/ 100.0 a)
Infinity
boot.user=> (/ 100.0 b)
Infinity
I assume the analyzer must be promoting the first argument if it can determine the second one is double not long?
boot.user=> (/ 100 ^double b)
Infinity
boot.user=> (/ 100 ^double a)
Infinity
something in the analyzer must be able to take a shortcut if it knows ahead of time it'll be doing number division instead of integer division
from a class disassembly, if the second arg is a result of get
or in a var, it’s just an Object, so it goes to https://github.com/clojure/clojure/blob/clojure-1.8.0/src/jvm/clojure/lang/Numbers.java#L155
it’s hard to say that the divide(long,double)
variant is wrong per se, but I can see this causing someone confusion, if they say tried to replace a constant with a var
so I grep'd my project for korma.core/exec-raw calls and converted those queries to honeysql syntax; so far it worked with everything
A question, is there a way to use a function as generator in test.check
?
something that returns a generator that repeatedly calls the input (no-arg) function
it is not return
because I need it to call my function for fetching the value
but fmap
wants a function and a generator right?
so I just pass a random generator that I ignore in the function f
?
(tcgen/fmap (fn [_] (eutils/timestamp-now)) tcgen/does not matter)
ok I am trying, thanks!
your fmap-created generator will still depend on the original generator you're passing in the second argument for it's size tho
mmm...ok
(tcgen/generate (s/gen ::timestamp {::timestamp (tcgen/fmap (fn [_] (eutils/timestamp-now)) tcgen/large-integer)}))
I might be missing something ^
it does not seems to work like that
clojure.test.check.generators.Generator cannot be cast to clojure.lang.IFn
clojure.spec
I am following examples but there must be some trivial mistake
thanks a lot for your pair of eyes anyways 😄
@richiardiandrea why do you want to do this?
@gfredericks: just to have a consistend timestamp with the current time generated
I am open to other ways of course
why are your tests sensitive to the current time?
good question! they are not
i just wanted to see if I could do the same thing as in schema
what's schema?
https://github.com/plumatic/schema/blob/master/src/clj/schema/experimental/generators.clj#L19
they actually apply a little trick (first time I look at the source)
now I'm more confused
so in general you don't want to make generators using actually-random functions
because then you lose test.check's determinism and its shrinking capabilities
if you really really needed the current time in your test, I would say treat that the way you would any IO in tests, and don't make it part of the generator
yeah it was just out of curiosity...I will revert to good engineering in 10 minutes 😄
is there some capability of schema's generators that you're trying to emulate?
in any case the above does not work
the link I sent, g-by
allowed me to do (def url-gen (sgen/g-by #(str image-url "/test-" (rand-int 1000))))
so passing a function there with no args, no other input
I copied the code of function, it does not seem to work anymore...but it's not a big deal
(gen/->Generator (fn [_ _] (clojure.test.check.rose-tree/pure __get-a-value-somehow__)))
#donttrythisathome
#strictlyforYOLOpurposesonly
s/gen
doesn't take a map of generators, it takes a map of functions that returns a generator
oooooooooooooooooooh
lol thanks a lot @oahner
I think I need to call it a day
after this one 😄
don't worry, I read the function's docstring twice and still had dig deeper to find the issue, lol
I read it too a couple of times...now everything works as expected
I suppose fmap
ing with an impure function is a much easier way to do that isn't it
yes @gfredericks is now: {::timestamp #(tcgen/fmap (fn [_] (eutils/timestamp-now)) tcgen/large-integer)}
wrt the (/ 100 0.0)
thing from earlier, there is already a (old) bug on that: http://dev.clojure.org/jira/browse/CLJ-1142
Thanks @csm -- good to know there's an existing JIRA issue.
As you said in your comment, it does seem to be a bit of an edge case in practical terms, even tho' it's definitely weird.
i'm looking in the clojure.zipper code. Zippers store lots of information in meta. Is this a common paradigm? Seems unique to me at first glance
I wouldn't say unique but I think it's uncommon...
I'm new to clojure. Was reading through clojure.spec to write specs for existing clojure codebase. Any guidelines on organizing the specs?
As far as?
@freakynit: in terms of putting specs with the code they spec vs in separate files?
I think both can be appropriate. For clojure.core we’re putting them in clojure.core.specs. Sean put them in a separate namespace in java.jdbc to make them optional so as to support backwards compatibility to older versions of Clojure.
I also think putting them with the code is fine in other cases.
“domain” type data specs are probably a good fit for a separate file whereas function specs might be better with the code in some cases
some care does need to be taken in terms of dependency cycles if you have specs built on predicates etc
is there an alternative to https://github.com/cddr/integrity ?
a prismatic schema is just a data structure
what do you want to do with it?
hm yeah that'd be nice
FWIW, it looks as though the author has begun work on upgrading schema and has a branch in progress: https://github.com/cddr/integrity/issues/16#issuecomment-218929014
Is there a way to pass a class as a variable in a java static field invoke? i.e. (def c Integer) (.-MIN_VALUE c)
?
Say, is there a Clojure version of java.util.LinkedHashSet, eg a set that retains insertion ordering?
(I suppose I can just use a vector or something easily enough, I'm just curious)
Ah, found https://github.com/amalloy/ordered which has an implementation
hey all, is there really no function that "forces" a value to a certain range? i.e. something like (to-range 2 5 6) => 5
@timgilbert: If your keys in a set contain some sort of timing information you can use that in sorted-set-by
Hey gang… newb with lots of reading done, completed 4clojure, but no actual projects. I have an experiment I want to run and I’d like to use clojure but I don’t know if it’s suitable. Is it appropriate to ask for advice on that?
I want to fool around with neural nets for sentiment analysis - the plan is to record a bunch of tweets from the streaming twitter api, tagging tweets based on hashtag. I’ll have 10 or 15 happy hashtags (#blessed, #thrilled, etc) and some negative ones (#angry, #frustrated, etc) and tag the tweet accordingly.
I could write the code to collect the data from Twitter in about an hour in go, javascript, or python. It will probably take me 2 days in Clojure. 🙂
It’s worth it to me, if Clojure is an appropriate tool for this kind of experiment. But if it’s the wrong tool for the job, I should wait for another opportunity. Opinions on that? Clojure for reading streaming data from Twitter?
There exist a couple libraries which wrap the Twitter streaming APIs, but they weren't amazing when last I looked at them and they certainly predate core.async or most of the "modern" clojure streaming tooling.