Questions Concepts
GitHub icon


Clojure - Programming language

< >

Clojure is an open source programming language created in 2007 by Rich Hickey.

Source code:
git clone
#39on PLDB 16Years Old 82kRepos

Try now: Riju · TIO · Replit

Clojure ( , like "closure") is a dialect of the Lisp programming language. Clojure is a general-purpose programming language with an emphasis on functional programming. It runs on the Java virtual machine and the Common Language Runtime. Read more on Wikipedia...

Example from Riju:
(println "Hello, world!")
Example from hello-world:
(println "Hello World")
; Hello world in Clojure (defn hello [] (println "Hello world!")) (hello)
Example from Linguist:
(defn rand "Returns a random floating point number between 0 (inclusive) and n (default 1) (exclusive)." ([] (scm* [n] (random-real))) ([n] (* (rand) n)))
Example from Wikipedia:
;; A typical entry point of a Clojure program: ;; `-main` function (defn -main ; name [& args] ; (variable) parameters (println "Hello, World!")) ; body

Language features

Feature Supported Token Example
; -?\d+
; -?\d+\.\d+
; 0x-?[abcdef\d]+
MultiLine Comments (comment )
(comment A comment
Print() Debugging println
Line Comments ;
; A comment
Operator Overloading
(defmacro and
 "Evaluates exprs one at a time, from left to right. If a form
 returns logical false (nil or false), and returns that value and
 doesn't evaluate any of the other expressions, otherwise it returns
 the value of the last expr. (and) returns true."
 {:added "1.0"}
 ([] true)
 ([x] x)
 ([x & next]
  `(let [and# ~x]
     (if and# (and ~@next) and#))))
File Imports
(load "fun")
(load "files/fun")
(load-file "./files/fun.clj")
(defproject project-a
:dependencies [[org.clojure/clojure "1.5.1"]
              [project-b "0.1.0"]])
(require '[clojure.string :as string])
(use '[clojure.string :only [split]])
(import 'java.util.Date)
(require 'clojure.contrib.def 'clojure.contrib.except 'clojure.contrib.sql)
(require '(clojure.contrib def except sql))
Partial Application
(defn fun-full [x y] (+ x y))
(fun-full 2 3)
(def fun-half (partial fun-full 2))
(fun-half 3)
Strings "
"hello world"
Case Insensitive Identifiers X
Semantic Indentation X

View source

- Build the next great programming language · Search · Add Language · Features · Creators · Resources · About · Blog · Acknowledgements · Queries · Stats · Sponsor · Traffic · Traffic Today · Day 305 · · Logout