Program structure
Ranger uses parentheses for a call and braces for a block. A call has the operator or the function first, and the arguments after it.
print ("sum " + (1 + 2))A call on a dotted receiver can use the parentheses against the name.
helper.value() is the same call as (helper.value()).
A block holds one statement per line. { def c:int 5 return c } is a parse
error.
A class holds data and functions:
class Counter { def value:int 0
fn add:void (amount:int) { value = value + amount }
fn current:int () { return value }}| Keyword | Function |
|---|---|
class |
A class with data and functions. |
record |
A class that holds data only. The compiler writes a constructor that takes one argument per field, in the order of the fields. record Point { def x:int 0 def y:int 0 } gives (new Point(3 4)). A record is a reference on every target, like a class. |
systemclass |
A class that the target language gives. The compiler writes no code for it. |
fn |
A function of an object. |
sfn |
A static function of the class. |
def |
A variable or a property. |
Import |
Read another source file. |
Extend |
Add functions to a class that another file declares. |
Enum |
A set of named integer values. |
Entry point
Section titled “Entry point”The compiler starts the program from the static function main:
class Main { sfn main:void () { print "the program runs" }}Comments
Section titled “Comments”A comment starts with ; and continues to the end of the line.
; This line is a comment.def limit 10 ; This part of the line is also a comment.Blocks
Section titled “Blocks”Braces mark a block. A block is an argument of an operator, and the operator decides when the block runs.
if (limit > 5) { print "the limit is large"} { print "the limit is small"}The if operator has three arguments: the condition, the block for a true
condition and the block for a false condition. The third argument is optional.
Ranger 3.5.1 · commit f323fd4 · development build