Questions tagged [clojure]

Clojure is a modern Lisp dialect for the Java Virtual Machine (with versions for the CLR and JavaScript).

Clojure is a Lisp dialect for the Java Virtual Machine (with versions for the CLR and JavaScript).

Clojure is a modern Lisp dialect with an emphasis on functional programming (lazy/impure), running on the JVM with transparent access to all Java libraries, an interactive REPL development environment, dynamic runtime polymorphism, Lisp-style macro meta-programming and concurrent programming capabilities supported by software transactional memory.

Key features:

  • Lisp heritage - Clojure is a fully homoiconic language with support for macro-based metaprogramming. The full features of the language are available at compile time, and it is possible to manipulate "code as data". These mechanisms are frequently used to extend the language itself or create new domain-specific languages.
  • Functional programming - Clojure is primarily a functional language. It features immutable data structures and lazy sequences. Like many other Lisps, it is eagerly evaluated (although lazy sequences, macros and closures can be introduced to obtain lazy behavior) and impure.
  • Concurrent programming, supported by software transactional memory, and designed for multi-core environments.
  • Dynamic - Clojure is a dynamic language. However it should be noted that it is still fully compiled, exploits primitive operations on the JVM where needed for performance and can also support (optional) static type hints.
  • Hosted on the JVM, allowing for easy and transparent access to the wide ecosystem of Java libraries.
  • Open source - Clojure is run as a collaborative open source project (hosted on GitHub) and there is a rapidly growing ecosystem of open source libraries for Clojure, in addition to all the open source tools already available for Java
  • Portable - Clojure can run on any platform that supports the JVM, and Clojure versions are also available for the CLR (ClojureCLR) and JavaScript (ClojureScript)

Code Samples:

Hello world is simple....

  (println "Hello World!")

The "infamous" Lisp parentheses are used to apply a function, which is always the first item in the list:

  (+ 1 2 3 4)
  => 10 

Functions can easily be defined and passed to higher order functions like map:

  (defn triple [x]
    (+ x x x))

  (map triple [1 2 3 4 5 10])
  => (3 6 9 12 15 30)

Infinite lazy sequences are fully supported:

  (take 7 (iterate (partial str "a") "b"))
  => ("b" "ab" "aab" "aaab" "aaaab" "aaaaab" "aaaaaab")

You can even do powerful computations on infinite sequences, such as defining the complete Fibonacci series:

  (def fibonaccis
    (lazy-cat [0 1] (map + fibonaccis (rest fibonaccis))))

  (take 10 fibonaccis)
  => (0 1 1 2 3 5 8 13 21 34)

Resources:

Clojure Web Frameworks

Clojure Video Tutorials

General Clojure

Clojure Web Development

ClojureScript

51 questions
12
votes
4 answers

Clojure code evaluation in org-mode produces no output

I am trying to run clojure code from my org file in order to do some literate programming. What is not working: When I execute the source code block I get No output produced. Sample src code block #+begin_src clojure (+ 2 2) #+end_src clojure What…
Jeel Shah
  • 195
  • 7
7
votes
2 answers

How can I quickly switch between source namespace and test namespace?

In Cider, I can use C-c , to run the tests for the current namespace. This will work whether I'm currently in the source namespace or the test namespace itself (and indeed, this magic behavior is discussed in detail in the README). Given that Cider…
Sam Estep
  • 449
  • 5
  • 20
5
votes
1 answer

CIDER, how to fix "No cljs REPLs in current session" error

I'm editing a ClojureScript file, and I have a working ClojureScript REPL in another buffer. But when I try to evaluate a form in my file ui.cljs, with C-c C-c, I get a beep an a message in the mini-buffer that says No cljs REPLs in current…
Rob N
  • 547
  • 2
  • 12
5
votes
3 answers

Running all tests in a leiningen project?

Is there a way, via cider or some other emacs extension, to run all of the tests in a leiningen project? cider has the function cider-test-run-tests which attempts to just run the tests related to the code in the current buffer. That's fine, but…
abingham
  • 927
  • 6
  • 18
5
votes
1 answer

cider-jack-in: Symbol's function definition is void: clojure-project-dir

When I run cider-jack-in the following error appears. Symbol's function definition is void: clojure-project-dir I am very new to Emacs and this is totally stumping me. Let me know if you need more information and I will provide.
Jason Basanese
  • 215
  • 2
  • 7
4
votes
7 answers

cider-jack-in: Symbol's function definition is void: clojure-project-dir with closure-mode installed

M-x (cider-jack-in) cider-jack-in: Symbol's function definition is void: clojure-project-dir lein run "Hello World!" cat ~/.lein/profiles.clj {:user {:plugins [[cider/cider-nrepl "0.14.0"]]}} clojure-mode is installed. I forked and…
Chip
  • 51
  • 1
  • 6
4
votes
1 answer

How to generate inline plot result for ob-clojure?

Question: How to generate inline plot image result in Org-mode babel clojure src block? I tried some ways: First way: use :results file :file "clojure-babel-figure-result.png" #+BEGIN_SRC clojure :session :results file :file…
stardiviner
  • 1,888
  • 26
  • 45
4
votes
2 answers

Deep eager macroexpansion

This works: (require 'clojure-mode) (when (member 'clojure-mode my-packages) (define-clojure-indent (-> 1) (->> 1))) This gives the error Wrong type argument: listp, 1: (when (member 'clojure-mode my-packages) (require 'clojure-mode) …
Resigned June 2023
  • 1,502
  • 15
  • 20
4
votes
0 answers

How can I properly reload my code from the REPL?

I have a src/example/foo.clj file: (ns example.foo) (defn my-fn [] (println "Hello, world!")) I can open it in Emacs and spin up a REPL using C-c M-j and play with it. I don't want to type long namespace names, so I alias the ones I need: user>…
Sam Estep
  • 449
  • 5
  • 20
3
votes
2 answers

Evaluate paragraph in cider

I'm new to Emacs (after 10+ years of Vim) and want to use it primarily for clojure. Coming from Lighttable, one thing I absolute liked was the way it evaluated just the right sections of code no matter where I am. This is basically: Evaluating a…
ClojureMostly
  • 225
  • 1
  • 5
3
votes
0 answers

Speedbar tag hierarchy in Clojure - organize manually with comments?

If I run speedbar and call (speedbar-add-supported-extension ".clj") in init.el, then I see my Clojure files in the speedbar, and I can expand them to show the function definitions inside, like this: What I don't like is that Emacs is grouping and…
Rob N
  • 547
  • 2
  • 12
3
votes
1 answer

When using `lisp-state`, how can we repeat an action like slurp, and bind a key to easily perform the repeat?

In vim, I frequently used the "." shortcut for repeating the last command. I found this extremely useful especially when working with clojure tools to do things like slurp-ing and barf-ing to refactor code. In Spacemacs, the clojure layer provides a…
fraxture
  • 338
  • 1
  • 13
3
votes
1 answer

Evaluating `org-babel-clojure` blocks returns all form evaluations

I'm trying to set up babel for use with Clojure according to http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html#org85bc1ec and I can evaluate code but when I evaluate a block with multiple forms in it it outputs all of the form…
3
votes
1 answer

Custom indentation for clojure macros in *.clj files

I'd like to know if there is a way to define the indentation for a custom macro within the clojure source file. It is possible to define the indentation using clojure-mode, but as far as I can tell, it has to be done using elisp as described here. …
Qudit
  • 828
  • 8
  • 16
2
votes
2 answers

Key binding to run Clojure code in running cider REPL and specified namespace

I have cider working just fine in Emacs with my Clojure code. I am following a tutorial that uses Cursive as the IDE; in the tutorial they were able to define a key binding to a line of code in a specific namespace. The command I want to run in the…
1
2 3 4