this page gives an overview of common closure scripting calls.
The following steps help you write your first clojure script:
1. Get Counterclockwise, the Eclipse plug-in at http://updatesite.counterclockwise.googlecode.com/hg (for more information, see Clojure's getting started page).
2. Then create a new Clojure project and a clojure file.
3. Add the following: (println "Hello, world").
4. Run as > clojure
More detailed info on Clojure syntax, see:
- primer: http://www.moxleystratton.com/article/clojure/for-non-lisp-programmers
- detailed quick reference: http://faustus.webatu.com/clj-quick-ref.html
- book: http://java.ociweb.com/mark/clojure/article.html
Clojure Philosophy
Clojure is a functional programming language. It provides the tools to avoid mutable state, provides functions as first-class objects, and emphasizes recursive iteration instead of side-effect based looping. Clojure is impure, in that it doesn't force your program to be referentially transparent, and doesn't strive for 'provable' programs. The philosophy behind Clojure is that most parts of most programs should be functional, and that programs that are more functional are more robust.
The naming convention in Clojure is to use all lowercase with hyphens separating words in multi-word names, unlike the Java convention of using camelcase.
Clojure makes heavy use of lazy evaluation. This allows functions to be invoked only when their result is needed. "Lazy sequences" are collections of results that are not computed until needed. This supports the efficient creation of infinite collections.
Common Syntax
Alternatively, see the Clojure Sample Code.
Built in forms | |
common arithmetic operations | |
comparisons | |
comment | |
functions | |
Lists | Lists can have zero or more items, enclosed in parentheses. The list's elements are delimited with a space. |
vector | immutable, between [] |
list | immutable, between () |
map | immutable, between {} |
sets | immutable, between #{} |
hash-map | immutable, between () |
set | |
get | |
def assoc dissoc merge- with doseq | |
looping | In the absence of mutable local variables, looping and iteration must take a different form than in languages with built-in for or while constructs that are controlled by changing state. In functional languages looping and iteration are replaced/implemented via recursive function calls. Many such languages guarantee that function calls made in tail position do not consume stack space, and thus recursive loops utilize constant space. |
sequence | A Sequence is not a data structure but an interface, or view, into a data structure. A sequence can be derived from a collection. The relation between collection and sequence is similar to the relation between database table and database view. sequence from a map: |
| |
Java integration | |
Automated tests | More clojure test examples. More info on clojure tests. |
|
Java integration
General | |
Static methods | |
Class and fields | |
Import | |
Create instance | |
Call instance methods | |
Call Java static methods | |
Chaining | |
Implementing interfaces and extending classes (use the reify macro): |
|
MySQL
(Alternatively, see the entire clojure MySQL demo code.)
|
Commands
|
Join
|
References
http://clojure.blip.tv/?sort=custom;date=;view=archive;user=clojure;nsfw=dc;s=posts;page=1