Enhance docstring example
This commit is contained in:
parent
b66c14fec6
commit
f812868c2b
2 changed files with 16 additions and 3 deletions
|
|
@ -949,12 +949,14 @@ Original by [@souenzzo](https://gist.github.com/souenzzo/a959a4c5b8c0c90df76fe33
|
||||||
|
|
||||||
### Print random docstring
|
### Print random docstring
|
||||||
|
|
||||||
|
See [examples/random_doc.clj](https://github.com/borkdude/babashka/blob/master/examples/random_doc.clj)
|
||||||
|
|
||||||
``` shell
|
``` 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])
|
([x])
|
||||||
Return true if x is a Keyword
|
Same as (first (first x))
|
||||||
```
|
```
|
||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
|
|
|
||||||
11
examples/random_doc.clj
Executable file
11
examples/random_doc.clj
Executable 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)
|
||||||
Loading…
Reference in a new issue