Urgent.News

What's breaking now, across thousands of outlets.

Tech

Clojure Explained: A Modern Lisp on the JVM

Introduction Lisp is the second-oldest programming language still in use, and most programmers have never written it — yet its ideas (code as data, functions as values, macros) shaped everything after it. Clojure, released in 2007, is Lisp rebuilt for the modern world: it runs on the JVM, uses every Java library, and replaces Lisp's mutable lists with immutable data structures. It is the language…

Lisp, the second-oldest programming language still in use, has influenced all subsequent languages with its core concepts: code as data, functions as values, and macros. Clojure, introduced in 2007, is Lisp redesigned for contemporary needs. It operates on the Java Virtual Machine (JVM), utilizes all Java libraries, and substitutes Lisp's mutable lists with immutable data structures.

The language has convinced many doubters that parentheses are not a hindrance but rather a defining feature. The essence of Clojure's design revolves around three fundamental ideas: immutable data as the default, code treated as data, and the interactive development environment (REPL).

Immutable data is the norm in Clojure. Data structures such as maps, vectors, and sets do not change in place. Instead, updating these structures results in a new version, enabling safe concurrent code execution and preserving old versions for future reference.

Clojure's unique approach of treating code as data allows programs to manipulate programs. For instance, macros, which are a staple in other languages often emulated through code generation, are intrinsic to Clojure. The REPL is the heart of Clojure's development workflow. It facilitates interactive evaluation of expressions, inspection of state, and the ability to reshape running programs without necessitating a restart. This REPL is not a mere tool; it is the core of the development process.

Clojure's compatibility with the JVM ensures seamless integration with all Java libraries. Consequently, Clojure applications can deploy anywhere Java is present, devoid of the ecosystem risks associated with niche runtimes. A concise example illustrates the essence of Clojure's programming style: defining a user as a map and a function to increment the user's age while returning a new map without altering the original data.

However, Clojure's allure comes with trade-offs. Programmers must adjust to parentheses and prefix notation, and the initial startup time is slower due to the JVM. Additionally, the talent pool is relatively small, which can be a limitation. Moreover, error messages, originating from the JVM stack, may be cryptic and challenging to interpret.

The guiding principle is to adopt Clojure when immutability and interactive development are paramount, especially for data processing pipelines and backend services. For projects where team familiarity is more critical, a mainstream JVM language may be a more suitable choice.

In summary, Clojure is a contemporary Lisp designed to run on the JVM. It champions immutable data, treats code as data, and emphasizes a REPL-driven development approach, all while maintaining compatibility with every Java library. The language opts for simplicity over familiarity, promising scalability in complexity. For skilled Clojure programmers, the peculiarities of parentheses gradually transform from perceived strangeness to a source of honest programming.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

I built a lantern for memories that never leave your device

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine . What I Built Legacy Lantern is a private remembrance studio.

  • Legacy Lantern is a private, in-browser remembrance studio
  • Users input name, relationship, favorite things, and a cherished memory
  • Memory stays on user's browser, never leaves the device

Objects in JS

Object is a non primitive data type to store functions and values. Multiple values as key:value pairs. Functions are stored as key:function() pairs called methods.

  • Objects in JavaScript store functions and values via key-value pairs.
  • Functions within objects are methods; objects encapsulate related information.
  • Properties accessed using dot or bracket notation; CRUD operations possible.

More from Tuesday 27 October →