Skip to content

Commit 70c0d43

Browse files
committed
Add List Functions For A Namespace as a clojure til
1 parent bb7ca94 commit 70c0d43

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77
warrant a full blog post. These are mostly things I learn by pairing with
88
smart people at [Hashrocket](http://hashrocket.com/).
99

10-
_419 TILs and counting..._
10+
_420 TILs and counting..._
1111

1212
---
1313

@@ -48,6 +48,7 @@ _419 TILs and counting..._
4848
- [Evaluate One Liners With lein-exec](clojure/evaluate-one-liners-with-lein-exec.md)
4949
- [Expanding Macros](clojure/expanding-macros.md)
5050
- [Get The Value Of An Environment Variable](clojure/get-the-value-of-an-environment-variable.md)
51+
- [List Functions For A Namespace](clojure/list-functions-for-a-namespace.md)
5152
- [Load A File Into The REPL](clojure/load-a-file-into-the-repl.md)
5253
- [Mapping With An Index](clojure/mapping-with-an-index.md)
5354
- [Open JavaDocs](clojure/open-javadocs.md)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# List Functions For A Namespace
2+
3+
You know that `clojure.string` has a function for uppercasing a string, but
4+
you can't quite remember the name of the function. You'd remember if you saw
5+
the name though. What you'd like to do is list all the functions in the
6+
`clojure.string` namespace to see if you can pick it out.
7+
8+
You can do just that. There are a couple ways to do it, in fact.
9+
10+
You can use the `dir` function with Clojure 1.6+. Alternatively, you can
11+
grab all the keys from the public intern mappings of the namespace.
12+
13+
```clojure
14+
> (dir clojure.string)
15+
blank?
16+
capitalize
17+
ends-with?
18+
escape
19+
includes?
20+
index-of
21+
join
22+
last-index-of
23+
lower-case
24+
re-quote-replacement
25+
replace
26+
replace-first
27+
reverse
28+
split
29+
split-lines
30+
starts-with?
31+
trim
32+
trim-newline
33+
triml
34+
trimr
35+
upper-case
36+
nil
37+
38+
> (keys (ns-publics 'clojure.string))
39+
(ends-with? capitalize reverse join replace-first starts-with? escape last-index-of re-quote-replacement includes? replace split-lines lower-case trim-newline upper-case split trimr index-of trim triml blank?)
40+
```
41+
42+
[source](http://stackoverflow.com/questions/2747294/how-to-list-the-functions-of-a-namespace)

0 commit comments

Comments
 (0)