Enhance docstring example

This commit is contained in:
Michiel Borkent 2020-02-20 12:45:44 +01:00
parent b66c14fec6
commit f812868c2b
2 changed files with 16 additions and 3 deletions

View file

@ -949,12 +949,14 @@ Original by [@souenzzo](https://gist.github.com/souenzzo/a959a4c5b8c0c90df76fe33
### Print random docstring
See [examples/random_doc.clj](https://github.com/borkdude/babashka/blob/master/examples/random_doc.clj)
``` shell
$ bb "(defmacro random-doc [] (let [sym (-> (ns-publics 'clojure.core) keys rand-nth)] \`(clojure.repl/doc ~sym))) (random-doc)"
$ examples/random_doc.clj
-------------------------
clojure.core/keyword?
clojure.core/ffirst
([x])
Return true if x is a Keyword
Same as (first (first x))
```
## Thanks

11
examples/random_doc.clj Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bb
(require '[clojure.repl])
(defmacro random-doc []
(let [sym (-> (ns-publics 'clojure.core) keys rand-nth)]
(if (:doc (meta (resolve sym)))
`(clojure.repl/doc ~sym)
`(random-doc))))
(random-doc)