Jump to content

Clojure Programming/Examples/API Examples

From Wikibooks, open books for an open world

This page gives example usage for Clojure API function calls. For a more general introduction to Clojure by example please see http://en.wikibooks.org/wiki/Clojure_Programming/By_Example

Documentation

[edit | edit source]

This page provides examples for the following functions.

Data Structures

[edit | edit source]

Numbers

[edit | edit source]
Computation + - * / inc dec min max rem rationalize
Comparison == < > <= >=
Predicates zero? pos? neg?

Strings

[edit | edit source]

Characters

[edit | edit source]

Advanced Data Structures

[edit | edit source]

Lists

[edit | edit source]

Vectors

[edit | edit source]

Struct Maps

[edit | edit source]

Array Maps

[edit | edit source]

Zippers

[edit | edit source]

Sequences

[edit | edit source]

Sequence Building

[edit | edit source]

Mapping Operators

[edit | edit source]

This page provides examples for the following functions.

Macros

[edit | edit source]

do Macros

[edit | edit source]

This page provides examples for the following functions.

Variable Definition

[edit | edit source]

This page provides examples for the following functions.

MultiMethod

[edit | edit source]

This page defines the following functions

Reference Tools

[edit | edit source]

This page defines the following functions.

Predicate functions

[edit | edit source]

This page provides examples for the following functions.

Recursion Tools

[edit | edit source]

This page defines the following functions.

Function Tools

[edit | edit source]

This page provides examples for the following functions.

Java Interaction

[edit | edit source]

This page provides examples for the following functions.

Namespaces

[edit | edit source]
(ns test.test 
  (:refer-clojure :exclude [+ -])) 
(defn + 
  [a b] 
  33) 
(+ 1 2) ;= 33 

require

[edit | edit source]
(require '[clojure.zip :as zip]) 
(require ['clojure.contrib.sql :as 'sql])

Misc.

[edit | edit source]
user=> (defn
  #^{:test (fn []
    (assert (= 4 (myadd 2 2))))}
  myadd [a b]
  (+ a b))
#'user/myadd
user=> (test #'myadd)
:ok