|Line 3:||Line 3:|
Latest revision as of 18:45, 23 June 2022
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. Numeric constants can be expressed in any base up to base 36 with the notation used by Clojure (e.g., "36rCRAZY" expresses a base 36 number with the digits "CRAZY", where the digits 0-9 are extended with A-Z following).
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).