Fork me on GitHub
#clojure
<
2016-05-07
>
slipset10:05:02

say I have a function (defn foo [] (into-array [""])), that is, a simple function which returns a java.lang.String array, how do I correctly type-annotate it?

slipset10:05:30

would (defn ^"[Ljava.lang.String;" foo [] (into-array [""])) be correct?

slipset10:05:18

the compiler doesn’t complain, neither does it for (defn ^"[Ljava.lang.String" foo [] (into-array [""]))

bronsa12:05:11

@slipset: the former is the correct version

bronsa12:05:31

the compiler unfortunately won't complain for wrong type hints

slipset12:05:01

Thanks @bronsa It would be nice with a typechecks? function though

bronsa12:05:56

it would be nice if the compiler did validate wrong type hints but .. ¯\(ツ)

slipset12:05:28

Sounds like that battle has been fought and lost?

Alex Miller (Clojure team)13:05:30

bronsa harps on this every chance he gets, but I'm not sure why really. It is intentional that types are treated as hints and thus can attribute the incorrect type without an error. However, it seems totally ok to me to error on badly formed or incorrectly placed types. Primitive type hints are a little trickier since they are not just hints but also affect the generated code.

bronsa13:05:18

I "harp" on this because I think that having the compiler error on provably wrong programs at compile time can only be beneficial to the programmer, I don't think it's a controversial opinion to hold

bronsa13:05:07

and also because the compiler already does "validate" (well, it crashes) type hints in some cases, but not in others and I value consistency

bronsa13:05:03

nevermind the fact that bad type hints can cause runtime crashes at callsites that are often hard to understand

wei15:05:24

what’s the best way to add a dependency without restarting?

lvh15:05:10

Is there some standard for test naming for clojure.test? is it deftest xyzzy-test, test-xyzzy, or xyzzy-tests?

pbaille16:05:45

hello, everybody, I’ve got a little macro question

pbaille16:05:54

(defmacro def-hm [hm] `(do [email protected](for [[sym val] hm] `(def (symbol (name sym)) val)))) (macroexpand-1 '(def-hm {:a 1 😛 2})) (let [hm {:a 1 😛 2}] (macroexpand-1 '(def-hm hm)))

pbaille16:05:15

this macro makes defs given an hashmap

pbaille16:05:30

in the second case it return an error

pbaille16:05:45

because arg are not evaluated

pbaille16:05:58

how can I force evaluation?

bronsa16:05:25

don't use a macro

bronsa16:05:38

use a function and intern rather than def

lvh16:05:27

Wait, what is the “second case”? I’m not sure I understand the problem there

xcthulhu17:05:50

@pbaille: (for [[k v] defs] (intern *ns* k v))

xcthulhu17:05:12

This is vaguely what @bronsa is referring to.

slipset17:05:21

@wei if you use #cider and clj-refactor, there is M-x cljr-add-project-dependency. Life is so much better...

dilin17:05:35

hi, does anyone know how to write something to stdin when running the repl? i’m trying to use (read-line) to read from stdin

grav17:05:01

what do the -x version numbers mean? Eg [devcards “0.2.1-7”]

cddr23:05:16

@dilin echo foo |lein repl

cddr23:05:34

Or if you're already in a repl, I think you could write to *in*