From 70c0d43e97dd599049a5eb3a0132c68f46d77987 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 17 May 2016 16:22:57 -0500 Subject: [PATCH] Add List Functions For A Namespace as a clojure til --- README.md | 3 +- clojure/list-functions-for-a-namespace.md | 42 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 clojure/list-functions-for-a-namespace.md diff --git a/README.md b/README.md index d50aa43..934c147 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really warrant a full blog post. These are mostly things I learn by pairing with smart people at [Hashrocket](http://hashrocket.com/). -_419 TILs and counting..._ +_420 TILs and counting..._ --- @@ -48,6 +48,7 @@ _419 TILs and counting..._ - [Evaluate One Liners With lein-exec](clojure/evaluate-one-liners-with-lein-exec.md) - [Expanding Macros](clojure/expanding-macros.md) - [Get The Value Of An Environment Variable](clojure/get-the-value-of-an-environment-variable.md) +- [List Functions For A Namespace](clojure/list-functions-for-a-namespace.md) - [Load A File Into The REPL](clojure/load-a-file-into-the-repl.md) - [Mapping With An Index](clojure/mapping-with-an-index.md) - [Open JavaDocs](clojure/open-javadocs.md) diff --git a/clojure/list-functions-for-a-namespace.md b/clojure/list-functions-for-a-namespace.md new file mode 100644 index 0000000..f8c7c89 --- /dev/null +++ b/clojure/list-functions-for-a-namespace.md @@ -0,0 +1,42 @@ +# List Functions For A Namespace + +You know that `clojure.string` has a function for uppercasing a string, but +you can't quite remember the name of the function. You'd remember if you saw +the name though. What you'd like to do is list all the functions in the +`clojure.string` namespace to see if you can pick it out. + +You can do just that. There are a couple ways to do it, in fact. + +You can use the `dir` function with Clojure 1.6+. Alternatively, you can +grab all the keys from the public intern mappings of the namespace. + +```clojure +> (dir clojure.string) +blank? +capitalize +ends-with? +escape +includes? +index-of +join +last-index-of +lower-case +re-quote-replacement +replace +replace-first +reverse +split +split-lines +starts-with? +trim +trim-newline +triml +trimr +upper-case +nil + +> (keys (ns-publics 'clojure.string)) +(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?) +``` + +[source](http://stackoverflow.com/questions/2747294/how-to-list-the-functions-of-a-namespace)