Basics
Raven's surface syntax should feel familiar if you've used any curly-brace language. This page covers the fundamentals; later chapters go deeper on each topic.
# a comment
println("Cacaw, World!")
(1 + 2.5) / 3
When running a file, lines are evaluated one by one, so println("hello") is a complete script – there's no main function.
Literals
Integers are a series of digits, 64-bit by default. Floats have a .. You can use _ as a separator, and 0x for hexadecimal.
x = 1500
y = 3.141
big = 1_000_000
mask = 0xCAFE_BABE
Strings live in double quotes, with the usual escapes; there's much more in the Strings chapter.
s = "Hello, World!"
Booleans are true and false, and nil is the value of "nothing here" – it's what empty functions and loops evaluate to.
Lists use square brackets, and are indexed from 1:
xs = [1, "foo", []]
xs[2] # "foo"
Comments
Single-line comments start with # and run to the end of the line. That's the only comment syntax.
Identifiers
Identifiers are alphanumeric, with _, ? and ! also allowed. By convention we use camelCase, with ? for predicates and ! for functions that work by side effect, eg even?(number) or put!(channel, x).
Function calls and operators
Calls look conventional: f(a, b). Operators are functions too, called with infix notation:
> (5^2) + 1
26
The arithmetic operators ^, *, /, +, - have their usual precedence (^ binds tightest), followed by comparisons (==, !=, <, >, <=, >=), then &&, then ||. Comparisons don't chain: 1 == 2 == 3 is a parse error, not false. And not every pair of operators has a defined precedence – where the combination would be ambiguous, Raven asks you to add parentheses rather than guessing.
&& and || short-circuit: a && b only evaluates b if a is true, and a || b only evaluates b if a is false.
Statements and blocks
The statement separator is a comma , or a newline – not a semicolon. Conceptually, blocks {...} are just lists of statements. In fact, there is no difference to the parser between {a, b, c}, [a, b, c] and (a, b, c) – you can write a multi-statement block on one line as i = {println(i), i+1}, or a list spread over several:
xs = [
1
2
3
]
Almost everything is an expression. An if produces the value of the branch taken, a block produces its last statement, and things with no other meaningful value – println, loops, empty functions – produce nil.
show
While you're exploring, the show macro is your friend: it prints an expression along with its value.
> show 2+2
(2 + 2) = 4
Next up: Variables & Scope.