Mercurial > lasercutter
view src/clojure/contrib/test_contrib/pprint/examples/show_doc.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line source
1 ;;; show_doc.clj -- part of the pretty printer for Clojure3 ;; by Tom Faulhaber4 ;; April 3, 20096 ; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved.7 ; The use and distribution terms for this software are covered by the8 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)9 ; which can be found in the file epl-v10.html at the root of this distribution.10 ; By using this software in any fashion, you are agreeing to be bound by11 ; the terms of this license.12 ; You must not remove this notice, or any other, from this software.14 ;; This example uses cl-format as part of a routine to display all the doc15 ;; strings and function arguments from one or more namespaces.17 (ns clojure.contrib.pprint.examples.show-doc18 (:use clojure.contrib.pprint))20 (defn ns-list21 ([] (ns-list nil))22 ([pattern]23 (filter24 (if pattern25 (comp (partial re-find pattern) name ns-name)26 (constantly true))27 (sort-by ns-name (all-ns)))))29 (defn show-doc30 ([] (show-doc nil))31 ([pattern]32 (cl-format33 true34 "~:{~A: ===============================================~35 ~%~{~{~a: ~{~a~^, ~}~%~a~%~}~^~%~}~2%~}"36 (map37 #(vector (ns-name %)38 (map39 (fn [f]40 (let [f-meta (meta (find-var (symbol (str (ns-name %)) (str f))))]41 [f (:arglists f-meta) (:doc f-meta)]))42 (filter43 (fn [a] (instance? clojure.lang.IFn a))44 (sort (map key (ns-publics %))))))45 (ns-list pattern)))))47 (defn create-api-file [pattern out-file]48 (with-open [f (java.io.FileWriter. out-file)]49 (binding [*out* f]50 (show-doc pattern))))