liveBook · Manning

Dir

As explained in Clojure: The Essential Reference

dir-fn is a Clojure function that returns the public definitions declared in a namespace as a sequence.

dir-fn is a clojure.repl function for discovering a namespace’s public definitions. It returns those names as a sequence, making the result suitable for further processing instead of only displaying it. section 22.3 section 16.2

Use dir-fn when namespace contents need to be inspected programmatically:

  • Require clojure.repl and pass a quoted namespace, because dir-fn is a function. section 22.3
  • Receive an ordered sequence of public definitions declared in that namespace. section 22.3
  • Prefer dir when direct REPL output is sufficient; dir prints the names rather than returning them for manipulation. section 22.3

Turn namespace definitions into a string

(require 'clojure.java.browse)\n(require '[clojure.repl :refer [dir-fn]])\n\n(apply str (interpose "," (dir-fn 'clojure.java.browse)))\n;; "*open-url-script*,browse-url"

How Clojure: The Essential Reference covers it

How deep it goes
Defines the returned sequence, ordered public names, quoted namespace input, and contrast with dir, without descending into implementation internals.
Examples
Demonstrates listing clojure.java.browse definitions and joining the returned names with interpose and apply.
What it assumes
Assumes familiarity with namespaces, quoted symbols, requiring namespaces, and basic sequence operations.
What you can do after
Apply it via clojure.repl/dir-fn to obtain and transform a namespace’s public definition names.
How it connects
Connects namespace inspection with vars, symbols, clojure.repl, and the related dir utility.

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.