This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-06-30
Channels
- # admin-announcements (19)
- # announcements (4)
- # beginners (22)
- # boot (76)
- # cider (92)
- # clojure (235)
- # clojure-berlin (3)
- # clojure-germany (1)
- # clojure-italy (8)
- # clojure-japan (18)
- # clojure-russia (26)
- # clojure-sg (1)
- # clojure-uk (25)
- # clojurescript (55)
- # code-reviews (7)
- # core-async (53)
- # datomic (13)
- # euroclojure (63)
- # jobs (39)
- # ldnclj (45)
- # off-topic (9)
- # om (7)
- # onyx (6)
- # reading-clojure (1)
- # reagent (5)
- # yada (22)
Is there any way to coerce types in defrecord
can I define a defrecord
with particular parameter type
and even when I pass a string it will be parsed to float?
hello, I have a question more related to lein than to Clojure, so I'm not sure if it is the right place to post... I'm trying to use lein at work but we are behind some kind of crazy proxy that change ssl certificates on the fly. I was able to install lein by defining variables HTTP[S]_PROXY using curl's --insecure option. The problem now, is that lein is not using curl anymore and fails to download files because of this. So, my question is how can we tell lein to ignore certificate when downloading ?
kamillelonek: the only types you can force in a defrecord are long or double via type hints on the fields: (defrecord R [^long a ^double b])
everything else is an object
I did that
but even then there was no coercion
well, I'm quite sure that using ^long and ^double hints will yield a Java object with long or double fields. what do you mean by coercion?
I mean implicit type conversion
without exlipicilty parsing it like Float/parseFloat
I mean String->Float
case
read-string
is said to be unsafe
oh, no you shouldn't expect that to ever happen automatically
ok, that is reasonable
the best way to do exactly that conversion is with Double/parseDouble (if you really want a primitive double) or Double/valueOf (if you're expecting a boxed number)
generally in Clojure, we don't ever use the Java Float type
there's very few cases when I would ever use it in Java either for that matter, the precision is too poor for almost anything useful.
I actually used:
(defn- build-model [[name gramms-from-milliliter]]
(let [gramms (bigdec gramms-from-milliliter)]
(->Ingredient name gramms)))
well that will work, but you get back a BigDecimal object, not a double. depending what you're doing with it, they perform a lot differently.
but it has the benefit of arbitrary precision, so that may be what you want