Clojure

From Just Solve the File Format Problem
Revision as of 19:51, 18 June 2022 by Dan Tobias (Talk | contribs)

Jump to: navigation, search
File Format
Name Clojure
Ontology
Extension(s) .clj, .edn

Clojure is a programming language based on LISP. It is designed for multithreaded applications with mutable and immutable data structures, and has implementations that run under Java or JavaScript. As with other Lisps, Clojure treats program code like data, making self-modifying code easy to develop. Functions in Clojure can be passed as arguments, and returned as values, by other functions.

While Clojure is a compiled language rather than an interpreted one, so there is no such thing as a "Clojure interpreter", in practice there are command line shells freely available that immediately compile any Clojure expressions typed in immediate mode and output their result, giving the "instant gratification" useful in climbing the learning curve when getting started in the language, a characteristic it has in common with old-time home computer BASICs as well as some newer languages like Python.

Though it's based on Lisp, the built-in function names were made more intuitive; gone are the traditional 'car' and 'cdr' (which were based historically on the register structure of the machine that Lisp was first implemented on in the 1950s) in favor of more understandable 'first' and 'rest' functions to return the first element and subsequent elements of a list respectively. So, baby, you can't drive its 'car'. There is, however, a 'trampoline' you can jump on; that's the name of a function that performs recursive calls on a function and subsequent functions returned as values by the previous function. Clojure attempts to handle recursion in a manner that doesn't require a huge stack, by converting it internally to something more akin to iteration while letting the programmer develop it with a recursive mindset.

You can also 'spit' and 'slurp' data while doing I/O; apparently nobody has taught Clojure table manners.

The concepts and terminology used in Clojure include "arity", the number of parameters a function takes (you can define a function with different functionality depending on what arity it is given in a particular invocation) and "closure", referring to a function enclosing temporary functions and other objects that are only in scope within the outer function, but have continued presence via their use in the outer function which can be invoked elsewhere.

As the implementations of Clojure in common use are built on Java, there are syntax conventions within Clojure for invoking Java objects and methods in a manner consistent with Clojure structure, so that application packages can combine Clojure and Java code. Java methods are still not Clojure functions, and can't be passed around in the same manner, though they can be wrapped in Clojure functions for such use.

.clj is the normal extension for Clojure programs, and .edn is also found in reference to Extensible Data Notation, a format used to express data used by Clojure (including programs themselves, which are merely a form of data).

Links

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox