Fork me on GitHub
#beginners
<
2016-10-20
>
shaun-mahood00:10:23

@jswart: Thanks, that really helps!

fingertoe04:10:59

I am doing an AWS lambda clojurescript function. I have some external .edn files I want to read and def as a map in my code. (slurp “ “) doesn’t seem to work in clojurescript — what is the normal protocol for such?

val_waeselynck06:10:12

@fingertoe if those files are resolved at compile time you can do it via JVM clojure using a macro

shooodooken09:10:40

@bwstearns hey thanks for reply. that's just a self contained example which captures the essence of what I'm trying to achieve. real code is not like that! 🙂

vandr0iy14:10:16

Hi, people! what's up with the odd issues with type conversions in clojure? If I write a function like this:

(defn ^long foo [] 6676046666777281638)
and then try to convert the result to double:
(double foo)
clojure doesn't like it, and spits out this:
CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core$long@77d55649
What's going on here? NOTE: it does not depend on the dimension of the number, - whether I write 65012734070871023874 or 5 I get the same result

vandr0iy14:10:52

and, the funny part comes when I try to convert it to long - it doesn't work either, spitting out the same error!

st14:10:29

I don’t know this area very well, but

user=> (defn ^Long foo [] 6676046666777281638)
#'user/foo
user=> (double (foo))
6.6760466667772815E18

donaldball14:10:43

foo isn’t a number ,it’s a fn

vandr0iy15:10:01

@donaldball sorry, I meant (double (foo)) @st sadly, changing the "foo" function is not an option - it belongs to a library

vandr0iy15:10:35

by the way, after some fiddling, I found the answer:

(double ^Long (foo))
no idea why the author of the library used (defn ^long ...) instead of (defn ^Long ...) though.

Alex Miller (Clojure team)18:10:01

the first example is not correct use of a type hint - var meta are evaluated so the long will actually resolve to the clojure.core/long function which is the result of the error

Alex Miller (Clojure team)18:10:11

you can see that if you (:tag (meta #’foo))

Alex Miller (Clojure team)18:10:18

(defn foo ^long [] 6676046666777281638) is what you want

Alex Miller (Clojure team)18:10:50

in this case the type hint is handled by the defn macro, which will not evaluate it

Alex Miller (Clojure team)18:10:35

if you really want it on the var you can do (defn ^{:tag 'long} foo [] 1)

Alex Miller (Clojure team)18:10:42

hinting it as ^Long is probably not what you actually want - that’s the Long wrapper object and will not give you the primitive return type performance that you likely want