This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-16
Channels
- # aws (6)
- # beginners (129)
- # calva (9)
- # cider (4)
- # cljs-dev (2)
- # clojure (41)
- # clojure-beijing (2)
- # clojure-dev (3)
- # clojure-spec (23)
- # clojure-uk (46)
- # clojurescript (38)
- # community-development (20)
- # core-async (4)
- # cursive (12)
- # data-science (7)
- # datascript (13)
- # datomic (15)
- # duct (11)
- # emacs (18)
- # figwheel-main (5)
- # fulcro (26)
- # off-topic (4)
- # pathom (28)
- # pedestal (3)
- # reagent (8)
- # reitit (6)
- # shadow-cljs (32)
- # specter (3)
Hi, is there a convention for writing docstring for a wrapper function wrapping a Java library?
Like should I use the Javadoc in the docstring, link to it? Any ideas?
@julien.rouse No conventions. There's no formatting associated with Clojure docstrings. They're usually just short statements of what a function does, occasionally with examples of usage. There are some documentation tools that will render Markdown in a Clojure docstring...
Thanks again Sean!
Looking for a function f
that makes the example =
true...
> 'component/start
component/start
> `component/start
com.stuartsierra.component/start
> (let [s 'component/start] (= (f s) `component/start)) ;; <--- looking for an f
resolve
?
You need the alias in scope to resolve the symbol:
user=> (require '[com.stuartsierra.component :as component])
user=> (->> (resolve 'component/start) meta ((juxt (comp str :ns) :name)) (map name) (apply symbol))
com.stuartsierra.component/start
user=>
Depends on the context you're trying to resolve symbols in I guess...
Interesting shortcut... FWIW, (resolve 'component/start)
produces a Var for me: #'com.stuartsierra.component/start
-- not sure why you didn't get that @vemv
> (resolve 'component/start)
is nil
I probably said (and eval'ed) that wrongly. getting the var indeed
Oh, I should have tried that first... that's a recent addition that you can go from a namespace object to a symbol I think...
Yeah, new in 1.10
seanc@DESKTOP-QU2UJ1N:~/clojure$ clj -Sdeps '{:deps {:com.stuartsierra/component {:mvn/version "RELEASE"}}}' -A1.9
Clojure 1.9.0
user=> (require '[com.stuartsierra.component :as component])
nil
user=> (resolve 'component/start)
#'com.stuartsierra.component/start
user=> (symbol *1)
ClassCastException clojure.lang.Var cannot be cast to java.base/java.lang.String clojure.core/symbol (core.clj:579)
user=>
seanc@DESKTOP-QU2UJ1N:~/clojure$ clj -Sdeps '{:deps {:com.stuartsierra/component {:mvn/version "RELEASE"}}}' -A1.10
Clojure 1.10.0
user=> (require '[com.stuartsierra.component :as component])
nil
user=> (resolve 'component/start)
#'com.stuartsierra.component/start
user=> (symbol *1)
com.stuartsierra.component/start
user=>
I tried doing (alter-meta! #'my-fn-name assoc 'clojure.core.protocols/Datafiable my-datafy-impl)
The metadata needs to be keyed on the function name, not the protocol type.
(alter-meta! #'my-fn-name assoc 'clojure.core.protocols/datafy my-datafy-impl)
I got that wrong too when I first tried it at Conj 🙂
OK, so that answers one question. the next is: is there a way to attach it to the function itself without rewriting defn
? 😬
I'm not sure what you're trying to do here... why do you want a function to be datafiable?
because now, (datafy #'my-fn-name)
works but (datafy my-fn-name)
obviously does not, since the meta is on the var not the fn
You could alter-var-root
to put in a new definition with metadata (wrapped on the function value, rather the Var) maybe?
Oh, because you no longer have access to the Var metadata itself?
is there an idiomatic way in clojure to check if a list has one and only one item? Other than (= (count my-list) 1)
Could also use (= 1 (bounded-count 2 my-list))
to avoid fully realizing large lazy sequences 🙂
@UCPGSBNQ4 ouh; good call; thanks!