API Overview - clojure-contrib v1.3 (in development)


The user contributions library, clojure.contrib, is a collection of namespaces each of which implements features that we believe may be useful to a large part of the clojure community.

This library was created by Rich Hickey but has been populated and is maintained by a group of volunteers who are excited about the success of the Clojure language and want to do our part to help it along. The current list of contributors is available on the clojure-contrib GitHub source page.

More contributions (and contributors) are welcome. If you wish to contribute, you will need to sign a contributor agreement (which allows Clojure and clojure.contrib to proceed without entanglements, see contributing for more info).

The best way to start is to share a project you've written with the google group and gauge the interest in adding it to contrib. (Publishing it in an open source form on google code, github or some other easy-to-access place in the net will also help.) After general discussion, Rich Hickey makes the final determination about what gets added to clojure.contrib.

Some parts of clojure.contrib may migrate into clojure.core if they prove to be so generally useful that they justify being everywhere. (For example, condp started out as an extension in contrib, but was moved to core by popular acclamation.)

The exact role of clojure.contrib and the future of the Clojure environment (standard libraries, dependency models, packaging systems, etc.) is the subject of pretty much continuous discussion in the clojure google group and in #clojure on freenode. Feel free to join that discussion and help shape the ways Clojure is extended.

Like Clojure itself, clojure.contrib is made available under the Eclipse Public License (EPL). clojure.contrib is copyright 2008-2009 Rich Hickey and the various contributors.

Important clojure-contrib resources




accumulators

by Konrad Hinsen
Detailed API documentation
A generic accumulator interface and implementations of various
accumulators.
Public variables and functions: add-items empty-counter empty-counter-with-total empty-list empty-map empty-maximum empty-mean-variance empty-min-max empty-minimum empty-product empty-queue empty-set empty-string empty-sum empty-tuple empty-vector


agent-utils

by Christophe Grande
Detailed API documentation
Miscellaneous agent utilities
(note to other contrib members: feel free to add to this lib)
Public variables and functions: capture-and-send


base64

by Stuart Sierra
Detailed API documentation
Base-64 encoding and decoding.  

This is mainly here as an example.  It is much slower than the
Apache Commons Codec implementation or sun.misc.BASE64Encoder.
Public variables and functions: decode decode-str encode encode-str


classpath

by Stuart Sierra
Detailed API documentation
Utilities for dealing with the JVM's classpath
Public variables and functions: classpath classpath-directories classpath-jarfiles


combinatorics

by Mark Engelberg
Detailed API documentation
Efficient, functional algorithms for generating lazy
sequences for common combinatorial functions. (See the source code 
for a longer description.)
Public variables and functions: cartesian-product combinations lex-permutations permutations selections subsets


command-line

by Chris Houser
Detailed API documentation
Process command-line arguments according to a given cmdspec
Public variables and functions: with-command-line


complex-numbers

by Konrad Hinsen
Detailed API documentation
Complex numbers
NOTE: This library is in evolution. Most math functions are
      not implemented yet.
Public variables and functions:


cond

by Stephen C. Gilardi
Detailed API documentation
Extensions to the basic cond function.
Public variables and functions: cond-let


condition

by Stephen C. Gilardi
Detailed API documentation
Flexible raising and handling of conditions:

Functions:

              raise: raises a condition
       handler-case: dispatches raised conditions to appropriate handlers
  print-stack-trace: prints abbreviated or full condition stack traces

Data:

  A condition is a map containing values for these keys:

    - :type, a condition type specifier, typically a keyword
    - :stack-trace, a stack trace to the site of the raise
    - :message, a human-readable message (optional)
    - :cause, a wrapped exception or condition (optional)
    - other keys given as arguments to raise (optional)

Note: requires AOT compilation.

Based on an idea from Chouser:
http://groups.google.com/group/clojure/browse_frm/thread/da1285c538f22bb5
Public variables and functions: *full-stack-traces* handler-case print-stack-trace raise

Variables and functions in condition.Condition: -init -meta -post-init


core

by Laurent Petit (and others)
Detailed API documentation
Functions/macros variants of the ones that can be found in clojure.core 
(note to other contrib members: feel free to add to this lib)
Public variables and functions: -?> -?>> .?. dissoc-in new-by-name seqable?


dataflow

by Jeffrey Straszheim
Detailed API documentation
A library to support a dataflow model of state
Public variables and functions: add-cell-watcher add-cells build-dataflow build-source-cell build-standard-cell build-validator-cell cell display-cell eval-cell get-cell get-cells get-old-value get-source-cells get-value get-value-from-cell get-values print-dataflow remove-cells source-cell? update-values


datalog

by Jeffrey Straszheim
Detailed API documentation
A Clojure implementation of Datalog
Public variables and functions: build-work-plan run-work-plan

Variables and functions in datalog.database: add-index add-relation add-tuple add-tuples any-match? database-counts database-merge database-merge-parallel datalog-relation ensure-relation get-relation make-database merge-relations remove-tuple replace-relation select

Variables and functions in datalog.literals: build-atom build-seed-bindings delta-literal get-adorned-bindings get-base-predicate literal-magic? magic-literal negated-literal negated? positive? project-literal

Variables and functions in datalog.magic: adorn-query adorn-rules-set build-partial-tuple magic-transform seed-predicate-for-insertion seed-relation seed-rule

Variables and functions in datalog.rules: <- ?- all-predicates apply-rule compute-sip display-query display-rule is-safe? make-rules-set non-base-rules predicate-map return-rule-data rules-set

Variables and functions in datalog.softstrat: build-soft-strat-work-plan get-all-relations

Variables and functions in datalog.util: is-query-var? is-var? keys-to-vals map-values preduce reverse-map trace-datalog


def

by Stephen C. Gilardi
Detailed API documentation
def.clj provides variants of def that make including doc strings and
making private definitions more succinct.
Public variables and functions: defalias defhinted defmacro- defn-memo defnk defonce- defstruct- defunbound defunbound- defvar defvar- name-with-attributes


error-kit

by Chris Houser
Detailed API documentation
EXPERIMENTAL
System for defining and using custom errors
Please contact Chouser if you have any suggestions for better names
or API adjustments.
Public variables and functions: bind-continue deferror do-not-handle error handle raise raise* throw-msg with-handler


except

by Stephen C. Gilardi
Detailed API documentation
Provides functions that make it easy to specify the class, cause, and
message when throwing an Exception or Error. The optional message is
formatted using clojure.core/format.
Public variables and functions: throw-arg throw-if throw-if-not throwf


fcase

by Stuart Sierra
Detailed API documentation
This file defines a generic "case" macro called "fcase" which takes
the equality-testing function as an argument.  It also defines a
traditional "case" macro that tests using "=" and variants that
test for regular expressions and class membership.


Note (December 23, 2008): This library has been supplanted by the
inclusion of "condp" in clojure.core as of Clojure SVN rev. 1180.
Public variables and functions: case fcase in-case instance-case re-case


find-namespaces

by Stuart Sierra
Detailed API documentation
Search for ns declarations in dirs, JARs, or CLASSPATH
Public variables and functions: clojure-source-file? clojure-sources-in-jar comment? find-clojure-sources-in-dir find-namespaces-in-dir find-namespaces-in-jarfile find-namespaces-on-classpath find-ns-decls-in-dir find-ns-decls-in-jarfile find-ns-decls-on-classpath ns-decl? read-file-ns-decl read-ns-decl read-ns-decl-from-jarfile-entry


fnmap

by Stuart Sierra
Detailed API documentation
Maps that dispatch get/assoc to user-defined functions.

Note: requires AOT-compilation
Public variables and functions: fnmap


gen-html-docs

by Craig Andera
Detailed API documentation
Generates a single HTML page that contains the documentation for
one or more Clojure libraries.
Public variables and functions: generate-documentation generate-documentation-to-file


generic.arithmetic

by Konrad Hinsen
Detailed API documentation
Generic arithmetic interface
This library defines generic versions of + - * / as multimethods
that can be defined for any type. The minimal required 
implementations for a type are binary + and * plus unary - and /.
Everything else is derived from these automatically. Explicit
binary definitions for - and / can be provided for
efficiency reasons.
Public variables and functions: defmethod* qsym


generic.collection

by Konrad Hinsen
Detailed API documentation
Generic arithmetic interface
This library defines generic versions of common
collection-related functions as multimethods that can be
defined for any type.
Public variables and functions:


generic.comparison

by Konrad Hinsen
Detailed API documentation
Generic comparison interface
This library defines generic versions of = < > <= >= zero?
as multimethods that can be defined for any type. Of the
greater/less-than relations, types must minimally implement >.
Public variables and functions: max min


generic.functor

by Konrad Hinsen
Detailed API documentation
Generic functor interface (fmap)
Public variables and functions:


generic.math-functions

by Konrad Hinsen
Detailed API documentation
Generic math function interface
This library defines generic versions of common mathematical
functions such as sqrt or sin as multimethods that can be
defined for any type.
Public variables and functions: approx=


graph

by Jeffrey Straszheim
Detailed API documentation
Basic graph theory algorithms
Public variables and functions: add-loops component-graph dependency-list fixed-point get-neighbors lazy-walk post-ordered-nodes recursive-component? remove-loops reverse-graph scc self-recursive-sets stratification-list transitive-closure


greatest-least

by Vincent Foley
Detailed API documentation
Various functions for finding greatest and least values in a collection
Public variables and functions: all-greatest all-greatest-by all-least all-least-by greatest greatest-by least least-by


import-static

by Stuart Sierra
Detailed API documentation
Import static Java methods/fields into Clojure
Public variables and functions: import-static


jar

by Stuart Sierra
Detailed API documentation
Utilities for working with Java JAR files
Public variables and functions: filenames-in-jar jar-file?


java-utils

by Stuart Halloway, Stephen C. Gilardi, Shawn Hoover, Perry Trolard, Stuart Sierra
Detailed API documentation
A set of utilties for dealing with Java stuff like files and properties.

Design goals:

(1) Ease-of-use. These APIs should be convenient. Performance is secondary.

(2) Duck typing. I hate having to think about the difference between
    a string that names a file, and a File. Ditto for a ton of other 
    wrapper classes in the Java world (URL, InternetAddress). With these
    APIs you should be able to think about domain equivalence, not type
    equivalence.

(3) No bossiness. I am not marking any of these functions as private
    the docstrings will tell you the intended usage but do what works for you. 					

Feedback welcome!

If something in this module violates the principle of least surprise, please 
let me (Stu) and the Clojure community know via the mailing list.
Contributors:

Stuart Halloway
Stephen C. Gilardi
Shawn Hoover
Perry Trolard
Stuart Sierra
Public variables and functions: as-properties get-system-property read-properties set-system-properties with-system-properties write-properties


jmx

by Stuart Halloway
Detailed API documentation
JMX support for Clojure

Requires post-Clojure 1.0 git edge for clojure.test, clojure.backtrace.
This is prerelease.
This API will change.
Send reports to stu@thinkrelevance.com.

Usage
  (require '[clojure.contrib.jmx :as jmx])

What beans do I have?

  (jmx/mbean-names "*:*")
  -> #<HashSet [java.lang:type=MemoryPool,name=CMS Old Gen, 
                java.lang:type=Memory, ...]

What attributes does a bean have?

  (jmx/attribute-names "java.lang:type=Memory")
  -> (:Verbose :ObjectPendingFinalizationCount 
      :HeapMemoryUsage :NonHeapMemoryUsage)

What is the value of an attribute? 

  (jmx/read "java.lang:type=Memory" :ObjectPendingFinalizationCount)
  -> 0

Can't I just have *all* the attributes in a Clojure map?

  (jmx/mbean "java.lang:type=Memory")
  -> {:NonHeapMemoryUsage
       {:used 16674024, :max 138412032, :init 24317952, :committed 24317952},
      :HeapMemoryUsage
       {:used 18619064, :max 85393408, :init 0, :committed 83230720},
      :ObjectPendingFinalizationCount 0,
      :Verbose false}

Can I find and invoke an operation?

  (jmx/operation-names "java.lang:type=Memory")
  -> (:gc)  
  (jmx/invoke "java.lang:type=Memory" :gc)
  -> nil

What about some other process? Just run *any* of the above code
inside a with-connection:

  (jmx/with-connection {:host "localhost", :port 3000} 
    (jmx/mbean "java.lang:type=Memory"))
  -> {:ObjectPendingFinalizationCount 0, 
      :HeapMemoryUsage ... etc.}

Can I serve my own beans?  Sure, just drop a Clojure ref
into an instance of clojure.contrib.jmx.Bean, and the bean
will expose read-only attributes for every key/value pair
in the ref:

  (jmx/register-mbean
     (Bean.
     (ref {:string-attribute "a-string"}))
     "my.namespace:name=Value")
Public variables and functions: *connection* attribute-info attribute-names build-attribute-info guess-attribute-typename jmx-url map->attribute-infos maybe-atomize maybe-keywordize mbean mbean-names op-param-types operation operation-names operations raw-read read read-supported readable? with-connection


json

by Stuart Sierra
Detailed API documentation
JavaScript Object Notation (JSON) parser/writer.
See http://www.json.org/
To write JSON, use json-str, write-json, or write-json.
To read JSON, use read-json.
Public variables and functions: json-str pprint-json print-json read-json read-json-from write-json


lazy-seqs

by Stephen C. Gilardi
Detailed API documentation
==== Lazy sequences ====

 primes - based on the "naive" implemention described in [1] plus a
          small "wheel" which eliminates multiples of 2, 3, 5, and
          7 from consideration by incrementing past them. Also inspired
          by code from Christophe Grand in [2].

 fibs   - all the Fibonacci numbers

 powers-of-2 - all the powers of 2

 ==== Lazy sequence functions ====

 (partition-all, shuffle moved to clojure.core)
 (rand-elt moved to clojure.core/rand-nth)
 (rotations, rand-elt  moved to seq_utils.clj)
 (permutations and combinations moved to combinatorics.clj)

 [1] http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
 [2] http://clj-me.blogspot.com/2008/06/primes.html
Public variables and functions: fibs powers-of-2 primes


lazy-xml

by Chris Houser
Detailed API documentation
Functions to parse xml lazily and emit back to text.
Public variables and functions: parse-seq parse-trim


logging

by Alex Taggart, with contributions and suggestions by Chris Dean, Phil Hagelberg, Richard Newman, and Timothy Pratley
Detailed API documentation
Logging macros which delegate to a specific logging implementation. At
runtime a specific implementation is selected from, in order, Apache
commons-logging, slf4j, log4j, and finally java.util.logging.

Logging levels are specified by clojure keywords corresponding to the
values used in log4j and commons-logging:
  :trace, :debug, :info, :warn, :error, :fatal

Logging occurs with the log macro, or the level-specific convenience macros,
which write either directly or via an agent.  See log* for more details
regarding direct vs agent logging.

The log macros will not evaluate their 'message' unless the specific logging
level is in effect. Alternately, you can use the spy macro when you have code
that needs to be evaluated, and also want to output the code and its result to
the log.

Unless otherwise specified, the current namespace (as identified by *ns*) will
be used as the log-ns (similar to how the java class name is usually used).
Note: your log configuration should display the name that was passed to the
logging implementation, and not perform stack-inspection, otherwise you'll see
some ugly and unhelpful text in your logs.

Use the enabled? macro to write conditional code against the logging level
(beyond simply whether or not to call log, which is handled automatically).

You can redirect all java writes of System.out and System.err to the log
system by calling log-capture!.  To bind *out* and *err* to the log system
invoke with-logs.  In both cases a log-ns (e.g., "com.example.captured")
must be specified in order to namespace the output.

For those new to using a java logging library, the following is a very basic
configuration for log4j. Place it in a file called "log4j.properties"
and place that file (and the log4j JAR) on the classpath.
  log4j.rootLogger=WARN, A1
  log4j.logger.user=DEBUG
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  log4j.appender.A1.layout.ConversionPattern=%d %-5p %c: %m%n
The above will print messages to the console for :debug or higher if one is
in the user namespace, and :warn or higher in all other namespaces.
Public variables and functions: *force* *log-factory* *logging-agent* *tx-agent-levels* Log LogFactory commons-logging debug debugf enabled? error errorf fatal fatalf find-factory impl-enabled? impl-get-log impl-name impl-write! info infof java-util-logging log log* log-capture! log-stream log-uncapture! log4j-logging logf logp slf4j-logging spy trace tracef warn warnf with-logs


macro-utils

by Konrad Hinsen
Detailed API documentation
Local macros and symbol macros

Local macros are defined by a macrolet form. They are usable only
inside its body. Symbol macros can be defined globally
(defsymbolmacro) or locally (symbol-macrolet). A symbol
macro defines a form that replaces a symbol during macro
expansion. Function arguments and symbols bound in let
forms are not subject to symbol macro expansion.

Local macros are most useful in the definition of the expansion
of another macro, they may be used anywhere. Global symbol
macros can be used only inside a with-symbol-macros form.
Public variables and functions: defsymbolmacro deftemplate macrolet mexpand mexpand-1 mexpand-all symbol-macrolet with-symbol-macros


macros

by Konrad Hinsen
Detailed API documentation
Various small macros
Public variables and functions: const letfn- with-direct-linking


map-utils

by Jason Wolfe, Chris Houser
Detailed API documentation
Utilities for operating on Clojure maps.
Public variables and functions: deep-merge-with lazy-get safe-get safe-get-in


math

by Mark Engelberg
Detailed API documentation
Math functions that deal intelligently with the various
types in Clojure's numeric tower, as well as math functions
commonly found in Scheme implementations.

expt - (expt x y) is x to the yth power, returns an exact number
  if the base is an exact number, and the power is an integer,
  otherwise returns a double.
abs - (abs n) is the absolute value of n
gcd - (gcd m n) returns the greatest common divisor of m and n
lcm - (lcm m n) returns the least common multiple of m and n

The behavior of the next three functions on doubles is consistent
with the behavior of the corresponding functions
in Java's Math library, but on exact numbers, returns an integer.

floor - (floor n) returns the greatest integer less than or equal to n.
  If n is an exact number, floor returns an integer,
  otherwise a double.
ceil - (ceil n) returns the least integer greater than or equal to n.
  If n is an exact number, ceil returns an integer,
  otherwise a double.
round - (round n) rounds to the nearest integer.
  round always returns an integer.  round rounds up for values
  exactly in between two integers.


sqrt - Implements the sqrt behavior I'm accustomed to from PLT Scheme,
  specifically, if the input is an exact number, and is a square
  of an exact number, the output will be exact.  The downside
  is that for the common case (inexact square root), some extra
  computation is done to look for an exact square root first.
  So if you need blazingly fast square root performance, and you
  know you're just going to need a double result, you're better
  off calling java's Math/sqrt, or alternatively, you could just
  convert your input to a double before calling this sqrt function.
  If Clojure ever gets complex numbers, then this function will
  need to be updated (so negative inputs yield complex outputs).
exact-integer-sqrt - Implements a math function from the R6RS Scheme
  standard.  (exact-integer-sqrt k) where k is a non-negative integer,
  returns [s r] where k = s^2+r and k < (s+1)^2.  In other words, it
  returns the floor of the square root and the 
Public variables and functions: abs ceil exact-integer-sqrt expt floor gcd lcm round sqrt


miglayout

by Stephen C. Gilardi
Detailed API documentation
Clojure support for the MiGLayout layout manager
http://www.miglayout.com/

Example:

  (use '[clojure.contrib.miglayout.test :as mlt :only ()])
  (dotimes [i 5] (mlt/run-test i))
Public variables and functions: components miglayout

Variables and functions in miglayout.internal: add-components component? constraint? do-layout format-constraint format-constraints get-components parse-component-constraint parse-item-constraints


mmap

by Chris Houser
Detailed API documentation
Functions for memory-mapping files, plus some functions that use a
mmaped file for "normal" activies -- slurp, load-file, etc.
Public variables and functions: buffer-stream mmap slurp


mock

Detailed API documentation

  
  
  
  Public variables and functions:
  calls expect has-args has-matching-signature? make-arg-checker make-count-checker make-mock returns times validate-counts 

Variables and functions in mock.test-adapter: calls has-args has-matching-signature? make-arg-checker make-count-checker make-mock report-problem returns times validate-counts


monadic-io-streams

by Konrad Hinsen
Detailed API documentation
Monadic I/O with Java input/output streams
Defines monadic I/O statements to be used in a state monad
with an input or output stream as the state. The macro
monadic-io creates a stream, runs a monadic I/O statement
on it, and closes the stream. This structure permits the
definition of purely functional compound I/O statements
which are applied to streams that can never escape from the
monadic statement sequence.
Public variables and functions: flush print println read-char read-line read-lines skip-chars with-io-streams with-reader with-writer write


monads

by Konrad Hinsen
Detailed API documentation
This library contains the most commonly used monads as well
as macros for defining and using monads and useful monadic
functions.
See also: Monad tutorial part 1 Monad tutorial part 2 Monad tutorial part 3 Monad tutorial part 4 Monads in Clojure part 1 Monads in Clojure part 2
Public variables and functions: call-cc cont-m defmonad defmonadfn domonad fetch-state fetch-val identity-m m-chain m-fmap m-join m-lift m-map m-reduce m-seq m-until m-when m-when-not maybe-m maybe-t monad monad-transformer run-cont sequence-m sequence-t set-m set-state set-val state-m state-m-until state-t update-state update-val with-monad with-state-field writer-m


ns-utils

by Stephen C. Gilardi
Detailed API documentation
Namespace utilities
Public variables and functions: dir docs get-ns immigrate ns-vars print-dir print-docs vars


priority-map

by Mark Engelberg
Detailed API documentation
A priority map is very similar to a sorted map, but whereas a sorted map produces a
sequence of the entries sorted by key, a priority map produces the entries sorted by value.
In addition to supporting all the functions a sorted map supports, a priority map
can also be thought of as a queue of [item priority] pairs.  To support usage as
a versatile priority queue, priority maps also support conj/peek/pop operations.

The standard way to construct a priority map is with priority-map:
user=> (def p (priority-map :a 2 :b 1 :c 3 :d 5 :e 4 :f 3))
#'user/p
user=> p
{:b 1, :a 2, :c 3, :f 3, :e 4, :d 5}

So :b has priority 1, :a has priority 2, and so on.
Notice how the priority map prints in an order sorted by its priorities (i.e., the map's values)

We can use assoc to assign a priority to a new item:
user=> (assoc p :g 1)
{:b 1, :g 1, :a 2, :c 3, :f 3, :e 4, :d 5}

or to assign a new priority to an extant item:
user=> (assoc p :c 4)
{:b 1, :a 2, :f 3, :c 4, :e 4, :d 5}

We can remove an item from the priority map:
user=> (dissoc p :e)
{:b 1, :a 2, :c 3, :f 3, :d 5}

An alternative way to add to the priority map is to conj a [item priority] pair:
user=> (conj p [:g 0])
{:g 0, :b 1, :a 2, :c 3, :f 3, :e 4, :d 5}

or use into:
user=> (into p [[:g 0] [:h 1] [:i 2]])
{:g 0, :b 1, :h 1, :a 2, :i 2, :c 3, :f 3, :e 4, :d 5}

Priority maps are countable:
user=> (count p)
6

Like other maps, equivalence is based not on type, but on contents.
In other words, just as a sorted-map can be equal to a hash-map,
so can a priority-map.
user=> (= p {:b 1, :a 2, :c 3, :f 3, :e 4, :d 5})
true

You can test them for emptiness:
user=> (empty? (priority-map))
true
user=> (empty? p)
false

You can test whether an item is in the priority map:
user=> (contains? p :a)
true
user=> (contains? p :g)
false

It is easy to look up the priority of a given item, using any of the standard map mechanisms:
user=> (get p :a)
2
user=> (get p :g 10)
10
user=> (p :a)
2
user=> (:a p)
2

Priority maps derive much of their utility by providing priority-based seq.
Note that no guarantees are made about the order in which items of the same priority appear.
user=> (seq p)
([:b 1] [:a 2] [:c 3] [:f 3] [:e 4] [:d 5])
Because no guarantees are made about the order of same-priority items, note that
rseq might not be an exact reverse of the seq.  It is only guaranteed to be in
descending order.
user=> (rseq p)
([:d 5] [:e 4] [:c 3] [:f 3] [:a 2] [:b 1])

This means first/rest/next/for/map/etc. all operate in priority order.
user=> (first p)
[:b 1]
user=> (rest p)
([:a 2] [:c 3] [:f 3] [:e 4] [:d 5])

Priority maps support metadata:
user=> (meta (with-meta p {:extra :info}))
{:extra :info}

But perhaps most importantly, priority maps can also function as priority queues.
peek, like first, gives you the first [item priority] pair in the collection.
pop removes the first [item priority] from the collection.
(Note that unlike rest, which returns a seq, pop returns a priority map).

user=> (peek p)
[:b 1]
user=> (pop p)
{:a 2, :c 3, :f 3, :e 4, :d 5}

It is also possible to use a custom comparator:
user=> (priority-map-by (comparator >) :a 1 :b 2 :c 3)
{:c 3, :b 2, :a 1}

All of these operations are efficient.  Generally speaking, most operations
are O(log n) where n is the number of distinct priorities.  Some operations
(for example, straightforward lookup of an item's priority, or testing
whether a given item is in the priority map) are as efficient
as Clojure's built-in map.

The key to this efficiency is that internally, not only does the priority map store
an ordinary hash map of items to priority, but it also stores a sorted map that
maps priorities to sets of items with that priority.

A typical textbook priority queue data structure supports at the ability to add
a [item priority] pair to the queue, and to pop/peek the next [item priority] pair.
But many real-world applications of priority queues require more features, such
as the ability to test whether something is already in the queue, or to reassign
a priority.  For example, a standard formulation of Dijkstra's algorithm requires the
ability to reduce the priority number associated with a given item.  Once you
throw persistence into the mix with the desire to adjust priorities, the traditional
structures just don't work that well.

This particular blend of Clojure's built-in hash sets, hash maps, and sorted maps
proved to be a great way to implement an especially flexible persistent priority queue.

Connoisseurs of algorithms will note that this structure's peek operation is not O(1) as
it would be if based upon a heap data structure, but I feel this is a small concession for
the blend of persistence, priority reassignment, and priority-sorted seq, which can be
quite expensive to achieve with a heap (I did actually try this for comparison).  Furthermore,
this peek's logarithmic behavior is quite good (on my computer I can do a million
peeks at a priority map with a million items in 750ms).  Also, consider that peek and pop
usually follow one another, and even with a heap, pop is logarithmic.  So the net combination
of peek and pop is not much different between this versatile formulation of a priority map and
a more limited heap-based one.  In a nutshell, peek, although not O(1), is unlikely to be the
bottleneck in your program.

All in all, I hope you will find priority maps to be an easy-to-use and useful addition
to Clojure's assortment of built-in maps (hash-map and sorted-map).
Public variables and functions: priority-map priority-map-by


probabilities.finite-distributions

by Konrad Hinsen
Detailed API documentation
Finite probability distributions
This library defines a monad for combining finite probability
distributions.
Public variables and functions: certainly choose cond-dist-m cond-prob dist-m join-with make-distribution normalize prob uniform zipf


probabilities.monte-carlo

by Konrad Hinsen
Detailed API documentation
Monte-Carlo method support

Monte-Carlo methods transform an input random number stream
(usually having a continuous uniform distribution in the
interval [0, 1)) into a random number stream whose distribution
satisfies certain conditions (usually the expectation value
is equal to some desired quantity). They are thus
transformations from one probability distribution to another one.

This library represents a Monte-Carlo method by a function that
takes as input the state of a random number stream with
uniform distribution (see
clojure.contrib.probabilities.random-numbers) and returns a
vector containing one sample value of the desired output
distribution and the final state of the input random number
stream. Such functions are state monad values and can be
composed using operations defined in clojure.contrib.monads.
Public variables and functions: discrete exponential lognormal n-sphere normal normal-box-muller random-stream reject sample sample-mean sample-mean-variance sample-reduce sample-sum


probabilities.random-numbers

by Konrad Hinsen
Detailed API documentation
Random number streams

This library provides random number generators with a common
stream interface. They all produce pseudo-random numbers that are
uniformly distributed in the interval [0, 1), i.e. 0 is a
possible value but 1 isn't. For transformations to other
distributions, see clojure.contrib.probabilities.monte-carlo.

At the moment, the only generator provided is a rather simple
linear congruential generator.
Public variables and functions: lcg rand-stream


profile

by Stuart Sierra
Detailed API documentation
Simple code profiling & timing measurement.

Wrap any section of code in the prof macro, giving it a name, like this:

       (defn my-function [x y]
         (let [sum (prof :addition (+ x y))
               product (prof :multiplication (* x y))]
           [sum product]))

The run your code in the profile macro, like this:

       (profile (dotimes [i 10000] (my-function 3 4)))

Which prints a report for each named section of code:

          Name      mean       min       max     count       sum
      addition       265         0     37000     10000   2655000
multiplication       274         0     53000     10000   2747000

Times are measured in nanoseconds, to the maximum precision available
under the JVM.  See the function documentation for more details.
Public variables and functions: *enable-profiling* print-summary prof profile summarize with-profile-data


prxml

by Stuart Sierra
Detailed API documentation
Compact syntax for generating XML. See the documentation of "prxml" 
for details.
Public variables and functions: *html-compatible* *prxml-indent* prxml


reflect

Detailed API documentation

  
  
  
  Public variables and functions:
  call-method get-field 


repl-ln

by Stephen C. Gilardi
Detailed API documentation
A repl with that provides support for lines and line numbers in the
input stream.
Public variables and functions: print-repl-info repl repl-info repl-prompt set-repl-name set-repl-prompt stream-repl


repl-utils

by Chris Houser, Christophe Grand, Stephen Gilardi, Michel Salim
Detailed API documentation
Utilities meant to be used interactively at the REPL
Public variables and functions: *local-javadocs* *remote-javadocs* add-break-thread! add-local-javadoc add-remote-javadoc break-threads expression-info find-javadoc-url javadoc run run* show start-handling-break


seq

by Stuart Sierra (and others)
Detailed API documentation
Sequence utilities for Clojure
Public variables and functions: fill-queue find-first indexed positions rec-cat rec-seq rotations separate


server-socket

by Craig McDaniel
Detailed API documentation
Server socket library - includes REPL on socket
Public variables and functions: create-repl-server create-server


set

by Jason Wolfe
Detailed API documentation
Clojure functions for operating on sets (supplemental to clojure.set)
Public variables and functions: proper-subset? proper-superset?


singleton

by Stuart Sierra
Detailed API documentation
Singleton functions
Public variables and functions: global-singleton per-thread-singleton


sql

by Stephen C. Gilardi
Detailed API documentation
A Clojure interface to sql databases via jdbc.
See also: Example code
Public variables and functions: connection create-table delete-rows do-commands do-prepared drop-table find-connection insert-records insert-rows insert-values is-rollback-only set-rollback-only transaction update-or-insert-values update-values with-connection with-query-results

Variables and functions in sql.internal: connection* find-connection* get-connection print-sql-exception print-sql-exception-chain print-update-counts rollback throw-rollback transaction* with-connection* with-query-results*


stream-utils

by Konrad Hinsen
Detailed API documentation
Functions for setting up computational pipelines via data streams.

NOTE: This library is experimental. It may change significantly
      with future release.

This library defines:
- an abstract stream type, whose interface consists of the
  multimethod stream-next
- a macro for implementing streams
- implementations of stream for
  1) Clojure sequences, and vectors
  2) nil, representing an empty stream
- tools for writing stream transformers, including the
  monad stream-m
- various utility functions for working with streams

Streams are building blocks in the construction of computational
pipelines. A stream is represented by its current state plus
a function that takes a stream state and obtains the next item
in the stream as well as the new stream state. The state is
implemented as a Java class or a Clojure type (as defined by the
function clojure.core/type), and the function is provided as an
implementation of the multimethod stream-next for this class or type.

While setting up pipelines using this mechanism is somewhat more
cumbersome than using Clojure's lazy seq mechanisms, there are a
few advantages:
- The state of a stream can be stored in any Clojure data structure,
  and the stream can be re-generated from it any number of times.
  Any number of states can be stored this way.
- The elements of the stream are never cached, so keeping a reference
  to a stream state does not incur an uncontrollable memory penalty.

Note that the stream mechanism is thread-safe as long as the
concrete stream implementations do not use any mutable state.

Stream transformers take any number of input streams and produce one
output stream. They are typically written using the stream-m
monad. In the definition of a stream transformer, (pick s) returns
the next value of stream argument s, whereas pick-all returns the
next value of all stream arguments in the form of a vector.
Public variables and functions: defst defstream pick pick-all stream-drop stream-flatten stream-m stream-seq stream-type


strint

by Chas Emerick
Detailed API documentation
String interpolation for Clojure.
Public variables and functions: <<


swing-utils

Detailed API documentation

  
  
  
  Public variables and functions:
  action-translation-table add-action-listener add-key-typed-listener do-swing do-swing* do-swing-and-wait make-action make-menubar menu-constructor-dispatch 


trace

by Stuart Sierra, Michel Salim
Detailed API documentation
This file defines simple "tracing" macros to help you see what your
code is doing.
Public variables and functions: *trace-depth* deftrace dotrace trace trace-fn-call trace-indent tracer


types

by Konrad Hinsen
Detailed API documentation
General and algebraic data types
Public variables and functions: defadt deftype deftype- match


with-ns

by Stuart Sierra
Detailed API documentation
Temporary namespace macro
Public variables and functions: with-ns with-temp-ns


zip-filter

by Chris Houser
Detailed API documentation
System for filtering trees and nodes generated by zip.clj in
general, and xml trees in particular.
Public variables and functions: ancestors children children-auto descendants left-locs leftmost? right-locs rightmost?

Variables and functions in zip-filter.xml: attr attr= seq-test tag= text text= xml-> xml1->
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.