Menu

Differences from GolfScript

aditsu

While similar to GolfScript in many ways, CJam also has the following differences (probably an incomplete list):

  • Support for double (floating point) numbers
  • Character type, which also enables a clear distinction between strings and arrays of numbers
  • Adjacent letters and letters followed by digits are not automatically joined into a single identifier, but parsed separately (most identifiers are named with a single character, except some 2-character operators)
  • Simplified string syntax, using only double quotes and minimal escaping (similar to single-quoted strings in GolfScript)
  • Only standard variables (uppercase letters) can be assigned, and they are initialized with various useful values
  • Line comments start with "e#" rather than "#", or you can write comments as strings and pop them immediately
  • The input is not automatically placed on the stack; instead, there are operators for reading the input ("l", "r", "q")
  • There is no newline printed automatically after running the program
  • A lot of additional operators; some examples:
    • setting array values ("t")
    • converting values to specific types ("a", "c", "d", "i", "s")
    • "for" loops with a loop variable ("f")
    • "do-while" loops that do not pop the condition ("h")
    • short map and fold operations (":" and "f")
    • get from url ("g")
    • command-line arguments ("ea")
    • current time ("es", "et")
    • transliteration ("er")
  • The "%" operator with a block (map) is implemented differently, it works like "[{}/]" in CJam (but often there is no difference in practice)
  • The "." operator is renamed to "_"; dots are now used for double literals and vector operators
  • The "?" (power/find) operator is renamed to "#"
  • The "and" operator is renamed to "e&" (or "&" with a block)
  • The "or" operator is renamed to "e|" (or "|" with a block)
  • The "print" operator is renamed to "o"
  • The "n" built-in is replaced with the "N" variable (pre-assigned to the newline string)
  • The "rand" operator is renamed to "mr"
  • The "do" operator is renamed to "g"
  • The "while" operator is renamed to "w"
  • The "if" operator is renamed to "?"
  • The "abs" operator is renamed to "z"
  • The "zip" operator is renamed to "z" (overloaded)
  • The "base" operator is renamed to "b"
  • A few operators are not (yet) implemented, or do not (yet) have all the meanings they have in GolfScript, or just work a bit differently

Related

Wiki: Home
Wiki: Operators