Fork me on GitHub
#clojure
<
2017-10-01
>
Alex Miller (Clojure team)02:10:52

@eggsyntax I usually use intellij, then hit ctrl-h on the class to show the class hierarchy to answer this question

eggsyntax13:10:30

Thanks! I just got a Cursive license last week, basically just for the analysis tools…

kaosko03:10:04

any suggestions for a good library/pattern to control per-user long running operations (e.g. I have plenty of relatively per-user heavy file operations that cannot run in parallel, shouldn't be re-tried)?

beoliver06:10:19

does anyone know why I am getting a no matching method for the following?

(def buff1 (byte-array [1 2 3 4 5]))
(def buff2 (byte-array 5))
(System/arraycopy buff1 0 buff2 5)

beoliver06:10:23

CompilerException java.lang.IllegalArgumentException: No matching method: arraycopy

au-phiware06:10:30

Wrong arity? Missing length...

au-phiware07:10:28

Yep, you've only got 4 :)

beoliver07:10:59

Yeah, can't believe I missed that... 10 mins of googling because I didn't read the signature properly 😄

mike_ananev07:10:48

hi! what is idiomatic way to set type hint for fn return value? before fn name or before args vector?

mike_ananev07:10:44

(defn ^String foo [x] (str x)) or (defn foo ^String [x] (str x))

bronsa11:10:19

since clojure 1.8.0, always use the latter

mike_ananev14:10:03

can you tell, what was changed in 1.8.0? And where i can find recommendations about latter case?

bronsa14:10:41

1.8.0 fixed a bug where type hinting classes on the return vector wouldn't resolve them

au-phiware07:10:08

err, I'm pretty sure the second one is invalid (or does something else)

au-phiware07:10:54

^String is shorthand for ^{:tag String} which associates metadata to the proceeding symbol (the function name)

mike_ananev08:10:10

no, both are valid. i've checked in repl. both allow to avoid warn on reflection.

au-phiware08:10:10

Oh okay, cool, I hadn't seen it before :)

ivanpierre09:10:21

On the :arglist name is always first, but he makes some dancing at the beginning of defn definition to catch all the cases 😄

(def

 ^{:doc "Same as (def name (fn [params* ] exprs*)) or (def
    name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
    to the var metadata. prepost-map defines a map with optional keys
    :pre and :post that contain collections of pre or post conditions."
   :arglists '([name doc-string? attr-map? [params*] prepost-map? body]
                [name doc-string? attr-map? ([params*] prepost-map? body)+ attr-map?])
   :added "1.0"}
 defn (fn defn [&form &env name & fdecl]
        ;; Note: Cannot delegate this check to def because of the call to (with-meta name ..)
        (if (instance? clojure.lang.Symbol name)
          nil
          (throw (IllegalArgumentException. "First argument to defn must be a symbol")))
        (let [m (if (string? (first fdecl))
                  {:doc (first fdecl)}
                  {})
              fdecl (if (string? (first fdecl))
                      (next fdecl)
                      fdecl)
              m (if (map? (first fdecl))
                  (conj m (first fdecl))
                  m)
              fdecl (if (map? (first fdecl))
                      (next fdecl)
                      fdecl)
              fdecl (if (vector? (first fdecl))
                      (list fdecl)
                      fdecl)
              m (if (map? (last fdecl))
                  (conj m (last fdecl))
                  m)
              fdecl (if (map? (last fdecl))
                      (butlast fdecl)
                      fdecl)
              m (conj {:arglists (list 'quote (sigs fdecl))} m)
              m (let [inline (:inline m)
                      ifn (first inline)
                      iname (second inline)]
                  ;; same as: (if (and (= 'fn ifn) (not (symbol? iname))) ...)
                  (if (if (clojure.lang.Util/equiv 'fn ifn)
                        (if (instance? clojure.lang.Symbol iname) false true))
                    ;; inserts the same fn name to the inline fn if it does not have one
                    (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (.concat (.getName ^clojure.lang.Symbol name) "__inliner"))
                                                     (next inline))))
                    m))
              m (conj (if (meta name) (meta name) {}) m)]
          (list 'def (with-meta name m)
                ;;todo - restore propagation of fn name
                ;;must figure out how to convey primitive hints to self calls first
								;;(cons `fn fdecl)
								(with-meta (cons `fn fdecl) {:rettag (:tag m)})))))

ivanpierre09:10:30

The ^ char function is managed by the reader, that's why metadata cannot be first argument as it's already embedded in next symbol.

alex-dixon15:10:14

Is it possible to get any data out of a dereferenced var?

chrisjd15:10:57

Can you explain a bit more? Dereferencing a var yields data by itself.

alex-dixon17:10:49

Sorry. Like a name, or namespace, or anything at all really

alex-dixon17:10:17

Whether it’s a def or a defn

alex-dixon17:10:00

I’m not sure what can be called on it, other than apply and str

chrisjd20:10:08

Do you mean resolving a symbol to its bound value? ns-resolve might be what you’re looking for - e.g. (def a 123) (ns-resolve *ns* ‘a)

chrisjd20:10:15

Otherwise, as in all Lisps, names resolve to their values unless they’re quoted. => a is all you need.

lsenjov21:10:31

If it's dereferenced/resolved already, probably not. At that point you're looking at the value, not where it came from

didibus21:10:23

QUESTION: I've noticed that tools.logging doesn't seem to log the data map of ex-info, any way to have it log it also?

didibus21:10:16

I saw a JIRA for it, but it mentions the issue is that log4j2 calls getMessage and not toString, but I use Logback as the backend with SLF4J and I see the same behaviour

didibus21:10:38

Hum, actually this seems to be Logback's behaviour