beanz Magazine

Clojure

The Clojure programming language provides the simplicity of a Lisp programming language with the ability to run in the Java Virtual Machine (JVM).

After creating languages to make Common Lisp work with .Net and Java, in 2007 Rich Hickey began work on Clojure to port Lisp to run on the Java Virtual Machine (JVM) and handle concurrent data processing. This would allow Lisp programmers to write code that could run on any computer using the Java Virtual Machine. Common Lisp is a dialect of LISP, created in 1958 and the second oldest programming language.

After two years work on Clojure, Hickey released the language publicly in 2009. A community of developers joined in to evolve the language and provide support and documentation. Hickey serves as BDFL (Benevolent Dictator for Life) for the project. Clojure now runs on JVM, Common Runtime Language, and JavaScript engines.

What Makes Clojure Special?

Clojure allows programmers familiar with Lisp to leverage the power of JVM. And it allows Java developers to extend their deployment, debugging, and profiling skills using familiar tools but with a different language.

Hickey created Clojure to modernize the power of Common Lisp as a functional programming language while also working with the established Java platform. Clojure also needed to handle multiple computations at the same time.

To handle multiple computations, or concurrency, Clojure uses software transactional memory (STM) to control access to memory space when two or more processes need the same data or resources.. STM is an alternative to lock-based synchronization where memory space or other resource is locked then unlocked for each access request.

As a Lisp dialect, Clojure uses Polish prefix notation where the operators are placed before the operands. Instead of 3 + 2, for example, Clojure is written as + 3 2. Splitting the operator from the operand creates a two part binary expression — in this case, the + operator and the 3 2 operand — which can be used to create a tree structure made of pairs of operators and operands. These binary expressions are called S-expressions. They are a fundamental feature of LISP and its dialects.

S-expressions can use parentheses to clarify relationships between operators and operands nested inside each other. For example, (* (+ 3 2) (* 10 20)) is the same as ( (3 + 2) * (10 * 20) ) or (5 * 200) or 1000. In this example, the (+ 3 2) and (* 10 20) are operands and they each are an S-expression.

Designed as a functional programming language, a Clojure function will always return the same value for the same argument passed into the function. The state of the data is immutable with errors more easily traced. Object oriented programming organizes data into objects with the ability to change the data inside each object; as a result, an object might return different values for the same argument passed into the object.

Because of its integration with the Java Virtual Machine, Clojure can call code written in Java and Java code can call code written in Clojure. The language also uses macros to simplify code reuse and reduce errors. Instead of writing multiple code blocks, a single line of code can call the code block from multiple places in the code. For example, in Clojure, defn is a macro used to create and define functions.

How is Clojure Used?

While Clojure is a relatively new language, it has been widely adopted by companies big and small, traditional businesses like Walmart and Wall Street banks as well as new companies like Netflix, Twitter, Heroku, and Soundcloud.

The wide adoption of Clojure in the business world suggests the language is recognized as useful and stable. Clojure is a simple and concise language that requires programmers new to the language learn a sometimes different way of thinking than traditional Java programming.

The Clojure community also has created a number of libraries and frameworks, for example, to extend the language into web programming. There are various implementations of the language, for example, ClojureScript compiles to JavaScript code. In addition, there’s clojure-py for Python, clojure-scheme for Scheme, and ClojureC for the C programming language.

Learn More

Clojure

http://clojure.org/
http://clojure.org/rationale
https://clojuredocs.org/
https://github.com/clojure/clojure
https://www.reddit.com/r/clojure
http://clojure.org/cheatsheet
http://clojurekoans.com/
https://github.com/gigasquid/wonderland-clojure-katas
http://tryclj.com/
https://en.wikipedia.org/wiki/Clojure

Clojure for the Brave and True

http://www.braveclojure.com/
https://www.nostarch.com/clojure

Learn X in Y Minutes: Clojure

http://learnxinyminutes.com/docs/clojure/

Clojure Programming

https://en.wikibooks.org/wiki/Clojure_Programming

Clojure on the Curve

http://blog.juxt.pro/posts/clojure-curve.html

Clojure is Not for Geniuses

http://adambard.com/blog/clojure-is-not-for-geniuses/

Software Transactional Memory

https://en.wikipedia.org/wiki/Software_transactional_memory
http://goodmath.scientopia.org/2012/01/22/the-basics-of-software-transactional-memory/
http://chimera.labs.oreilly.com/books/1230000000929/ch10.html

Java Virtual Machine

https://en.wikipedia.org/wiki/Java_virtual_machine

Macros (Computer Science)

https://en.wikipedia.org/wiki/Macro_%28computer_science%29#Lisp_macros

S-expressions

https://en.wikipedia.org/wiki/S-expression

Common Lisp

https://en.wikipedia.org/wiki/Common_Lisp
https://common-lisp.net/

LISP

https://en.wikipedia.org/wiki/Lisp_%28programming_language%29

Polish Notation

https://en.wikipedia.org/wiki/Polish_notation

Concurrency

https://en.wikipedia.org/wiki/Concurrency_%28computer_science%29

Functional Programming

https://en.wikipedia.org/wiki/Functional_programming

Object-oriented Programming

https://en.wikipedia.org/wiki/Object-oriented_programming





Also In The December 2015 Issue

The history of an egg shaped outdoor sculpture made of electronic parts in Palo Alto, California.

Use a software app to invent neat things by mixing SAM wireless blocks. No wires and no code needed.

How to Build a Computer

Building your own computer is a great way to not only save money, and get more processing power, but also to learn about the less obvious parts of software programming.

We might think robots are a modern invention. But al-Jazari created amazing automatons in the thirteenth century. Today we would call him a maker.

The Google Cardboard project is a fun way to experience virtual reality with your phone and software apps.

Sumobots smash into each other and can be a fun project to create. Free plans are online. Upload your plan to services which send you the parts.

How our all girls high school robotics team designed then built a robot to compete in FIRST competitions next year.

This key part of electronics projects turns out to be easy to understand. Learn about breadboards by building a simple LED project with a 9V battery.

Learn more than a language. Learn skills you need to use the language. Options to suit the way you learn best.

Use dice from a board game or toy store to create difficult to crack passwords and phrases that you can remember.

Learning how to make, track, and complete goals also helps with school projects and personal projects.

An essay from the 1990s explores how software can be built like a cathedral or in groups like a bazaar.

The Clojure programming language provides the simplicity of a Lisp programming language with the ability to run in the Java Virtual Machine (JVM).

Beyond Microsoft Windows and Mac OSX there are many Linux operating systems used by programmers daily and built as open source.

Interesting stories about computer science, software programming, and technology found online since the last issue of the magazine.

Links from the bottom of all the December 2015 articles, collected in one place for you to print, share, or bookmark.