This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-01
Channels
- # beginners (15)
- # boot (3)
- # cider (10)
- # clara (2)
- # cljs-dev (19)
- # clojure (31)
- # clojure-uk (9)
- # clojurescript (60)
- # core-async (1)
- # datomic (10)
- # docs (4)
- # fulcro (5)
- # hoplon (33)
- # juxt (1)
- # luminus (1)
- # off-topic (3)
- # om (20)
- # parinfer (2)
- # portkey (61)
- # re-frame (6)
- # reagent (39)
- # shadow-cljs (18)
- # spacemacs (4)
- # specter (8)
@eggsyntax I usually use intellij, then hit ctrl-h on the class to show the class hierarchy to answer this question
Thanks! I just got a Cursive license last week, basically just for the analysis tools…
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)?
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)
Wrong arity? Missing length...
@au-phiware its arity 5...
Yep, you've only got 4 :)
Yeah, can't believe I missed that... 10 mins of googling because I didn't read the signature properly 😄
hi! what is idiomatic way to set type hint for fn return value? before fn name or before args vector?
(defn ^String foo [x] (str x)) or (defn foo ^String [x] (str x))
can you tell, what was changed in 1.8.0? And where i can find recommendations about latter case?
1.8.0 fixed a bug where type hinting classes on the return vector wouldn't resolve them
err, I'm pretty sure the second one is invalid (or does something else)
^String
is shorthand for ^{:tag String}
which associates metadata to the proceeding symbol (the function name)
no, both are valid. i've checked in repl. both allow to avoid warn on reflection.
Oh okay, cool, I hadn't seen it before :)
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)})))))
The ^ char function is managed by the reader, that's why metadata cannot be first argument as it's already embedded in next symbol.
Is it possible to get any data out of a dereferenced var?
Sorry. Like a name, or namespace, or anything at all really
Whether it’s a def or a defn
I’m not sure what can be called on it, other than apply and str
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)
Otherwise, as in all Lisps, names resolve to their values unless they’re quoted. => a
is all you need.
If it's dereferenced/resolved already, probably not. At that point you're looking at the value, not where it came from
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?