Menu

Data types and literals

aditsu

CJam uses the following data types:

  • Integer with unlimited size, implemented in java using long (64-bit signed integer) and BigInteger (arbitrary-precision integer), fluidly switching between them as needed. Example literals: 0, -99999, 123456789012345678901234567890
  • Double, corresponding to double in C/java. Example literals: 1.23, -.5, 1234567890.; note: scientific notation is not supported directly in literals, but "e" followed by a numeric literal is also implemented as an infix operator with a similar meaning, therefore in many cases you can achieve the same result.
  • Character, corresponding to char in java; not a fully numeric type like in C. Example literals: 'A, '$, '' - note the absence of a second single quote; the last example is the apostrophe/single quote character. There is no escape character.
  • Array, with string as a special case, implemented in java using ArrayList<Object>. Strings are just arrays of characters.
    Example string literals: "hello", "foo\"bar", "a\b", "backslash: \\" resulting in the strings: hello, foo"bar, a\b, backslash: \. The backslash character \ can be used for escaping double quotes and backslashes, nothing else. When followed by any other character, it is treated as a regular character.
    Other than strings, there is no special array literal. Arrays can be constructed like this: [1 2 "foo"] but the square brackets are actually operators and not part of the syntax.
  • Block - a program section delimited by { and } and treated as a single unit. Similar to code blocks in C/java, except blocks are first-class objects and can be assigned to variables (thus defining functions).

Related

Wiki: Home
Wiki: Syntax