Data Elements

This page summarizes some of Clojure's key concepts regarding data elements (ie, scalars). It also provides links to more detailed information.

In computing terminology, a Scalar is an atomic (indivisible) quantity that can hold only one value at a time. However, certain scalar types and instances may allow sub-divisions. For example, an ISO 8601 date string (eg, "2007-04-05T14:30") encodes an atomic time value, but it could be decomposed into characters (eg, \2), substrings (eg, "2007"), etc.

Booleans

Only two data types in Clojure are treated as false: nil (ie, Java Null) and false. Everything else (including true) is treated as true. Many functions return nil (rather than an empty list) when they have no data to report (eg, at the end of a List). This allows upstream functions to "loop until nil" on the data.

Numbers

Clojure's numeric types are all based on Java types (eg, BigInteger, Double, Integer), but some special behavior is supported.

Floating Point

Clojure uses Java's (64-bit, IEEE 754) Double and (arbitrary precision) BigDecimal formats for floating-point values (eg, 123.456). Values may be explicitly specified as BigDecimal (eg, 123.456M); they are promoted as needed to avoid overflow.

Integers

Clojure uses Java's (32-bit, two's complement) Integer and (arbitrary precision) BigInteger formats for integers (eg, 42). Values may be explicitly specified as BigInteger (eg, 42N); they are promoted as needed to avoid overflow.

Ratios

Ratios (rational numbers) are based on Java's Integer format, but have their own behavior. The Ratio 2/3 is actually defined as a pair of integers; it will only be "divided" to support interoperability, etc. Ratios are automatically simplified to lowest common denominator format (eg, 22/33 and 22/11 will become 2/3 and 2, respectively).

Text

Byte Arrays

Clojure is able to create arrays of (8-bit) bytes, using the byte-array function. See Data Collections for more information.

Characters

Clojure's Characters (eg, \A, \1, \!) are Java's (immutable) Character values.

Keywords

A Clojure Keyword is basically a Symbol, preceded by a colon (:). The value of a Keyword is equal to its name. So, for example, :foo has the value :foo.

Strings

Clojure uses Java's (immutable, Unicode) String formats. Character sequences can be produced by means of seq; other functions can be used to produce sequences of lines, tokens, etc.

Symbols

Symbols begin with a non-numeric character and can contain alphanumeric characters and '*', '+', '!', '-', '_', and '?' (other characters will be allowed eventually, but not all macro characters have been determined). '/' has special meaning; it can be used once in the middle of a symbol to separate the namespace from the name, e.g. my-namespace/foo. '/' by itself names the division function. '.' has special meaning - it can be used one or more times in the middle of a symbol to designate a fully-qualified class name, e.g. java.util.BitSet, or in namespace names. Symbols beginning or ending with '.' are reserved by Clojure. Symbols containing / or . are said to be 'qualified'. Symbols beginning or ending with ':' are reserved by Clojure. A symbol can contain one or more non-repeating ':'s.

-- clojure.org/reader#The Reader--Reader forms

A Symbol may or may not be bound to a value, but either bound or unbound Symbols may be stored as values, etc. See also Data_Elements.


This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r5 - 03 Mar 2013, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email