The disc Language : Language Reference

WARNING: This document will not teach you to program.

This document collects the basic commands, operators, and other good stuff the disc language has to offer in a no-nonsense listing. This will not teach you how to program, how to be a better programmer, or how to program differently. It's just a list of things and what they do. Thanks for your attention.

Commands

Variables

define ... as ...
  • Defines a new block-level constant. Constants cannot be updated.
  • Example: define PI as 3.14159
let ... be ...
  • Defines a new block-level variable. These variables can be updated.
  • Example: let clifford be "Big red dog"
update ... to ...
  • Updates variable with a new value. Update cannot change the value of defined constants.
  • Example: update count to count + 1

Flow Control (conditions and loops)

if ...
  • Runs containing code only if the condition is met.
  • Runs all code contained before "end"
  • Example:
    if count isEqualTo 3
        print: "Count is three"
    end
                                
else if ...
  • Runs containing code only if the previous condition is NOT met, and this condition is.
  • Runs all code contained before "end"
  • Example:
    if count isEqualTo 3
        print: "Count is three"
    else if count isGreaterThan 5
        print: "No, no, MUCH bigger than 3"
    end
                                
else
  • Runs containing code only if all previous conditions are NOT met.
  • Runs all code contained before "end"
  • Example:
    if count isEqualTo 3
        print: "Count is three"
    else if count isGreaterThan 5
        print: "No, no, MUCH bigger than 3"
    else
        print: "No, it's far smaller than 3"
    end
                                
loop while ...
  • Loops while the given condition is true.
  • Repeats the lines between "loop while" and "end"
  • Example:
    loop while count isLessThan 5
        print: join: "Looping to five. Current count: " count
    end
    
repeat while ...
  • Alias of "loop while"
  • Example:
    repeat while count isLessThan 5
        print: join: "Looping to five. Current count: " count
    end
    

Operators

Arithmetic

+, -, *, /
  • Addition, subtraction, multiplication, and division, respectively
  • Order of operations are as follows:
    1. Parenthetical grouping (parentheses)
    2. Multiplication and division (left to right priority)
    3. Addition and subtractions (left to right priority)

Comparison

... isLessThan ...
  • Produces true when the value on the left is less than the one on the right, otherwise false.
  • Compares number values only
  • Examples:
    5 isLessThan 12 # produces true
    7 isLessThan -3 # produces false
                            
... isLessOrEqualTo ...
  • Produces true when the value on the left is either less, or equal to than the one on the right, otherwise false.
  • Compares number values only
  • Examples:
    5 isLessOrEqualTo 12 # produces true
    7 isLessOrEqualTo 7 # produces true
    7 isLessOrEqualTo -2 # produces false
                            
... isGreaterThan ...
  • Produces true when the value on the left is less than the one on the right, otherwise false.
  • Compares number values only
  • Examples:
    5 isGreaterThan 12 # produces false
    7 isGreaterThan -3 # produces true
                            
... isGreaterOrEqualTo ...
  • Produces true when the value on the left is either less, or equal to than the one on the right, otherwise false.
  • Compares number values only
  • Examples:
    5 isGreaterOrEqualTo 12 # produces false
    7 isGreaterOrEqualTo 7 # produces true
    7 isGreaterOrEqualTo -2 # produces true
                            
... isEqualTo ...
  • Produces true when values are equal, otherwise false.
  • Compares number, and string values only
  • Examples:
    7 isEqualTo 7 # produces true
    "this is fine" isEqualTo "this is fine" # produces true
    7 isEqualTo -2 # produces false
    "this is fine" isEqualTo "this is not fine" # produces false
                            

Logical

... and ..., ... or ...
  • Evaluates truthiness of a boolean expression
  • Only works with boolean values
  • Examples:
    (count isLessThan 3) and (count isGreaterThan 0)
    (count isLessThan 3) or (count isGreaterThan 0)
                            

Other

...
  • Line continuation operator, yes it's '...'
  • Example:
                                    let numberIsInRange be ...
                                        number isLessThan 5 ...
                                        and number isGreaterThan -5
    
                                
declare function ... (withParameters ...)
  • Declares a new function, optionally with parameters
  • Example:
    declare function displayScore withParameters wins losses ties
        call clear
    
        print: join: "wins: " wins " losses: " losses " ties: " ties
    end
    
    declare function displayRandomNumber
        print: random: 0 100
    end
                                
call ... (with ...)
  • Calls a function, optionally with arguments
  • Examples:
    let myArray be (call newArray)
    let myArray be (call newArray with 1 2 3 4)
                                
...: ...
  • Shorthand for call
  • Examples:
    let myArray be (newArray:)
    let myArray be (newArray: 1 2 3 4)
                                
toInfix ...
  • Turns a function into an infix operator
  • Example:
    # without toInfix
    join: "a left-handed string" "a right-handed string"
    # with toInfix
    toInfix "a left-handed string" join "a right-handed string"
                                
:: ...
  • Shorthand for toInfix
  • Example:
    # without :: (toInfix)
    join: "a left-handed string" "a right-handed string"
    # with :: (toInfix)
    :: "a left-handed string" join "a right-handed string"
                                

Functions

Array

newArray (...)
appendTo ...
readFrom ...
removeFrom ...
setOn ...
lengthOf ...

Dictionary

newDictionary
hasKey ...
getKeysFrom ...
readFrom ...
removeFrom ...
setOn ...

Logic

not ...

Mathematical

numberToString ...
random (...)
absoluteValue ...
floor ...
ceiling ...
squareRoot ...
power ...
maximum ...
minimum ...
remainder ...
round ...
log ...

Nil

newNil
isNil ...

String

join ...
toLowerCase ...
toUpperCase ...
toArray ...
stringToNumber ...
getCharacterAtIndex ...
lengthOf ...

User Input/Output

print ...
clear
prompt ...
wait ...
readKey