corfli
Contents

Start

Language

Project

Operators

Arithmetic

a := 7
b := 2
print(a + b, a - b, a * b, a / b, a % b)
9 5 14 3 1

Dividing whole numbers gives a whole number, like in C: 7 / 2 is 3. The result is cut toward zero, so -7 / 2 is -3 and -7 % 2 is -1.

Changing a variable

n := 10
n += 40
n -= 5
n *= 2
n /= 3
n %= 7
print(n)
i := 0
i++
i++
i--
print(i)
2
1

x++ and x-- are statements on their own line. They can't be used inside a bigger expression, so there's no i++ versus ++i to remember.

Comparing

==, !=, <, <=, >, >= give a bool. They can't be chained: write a < b and b < c instead of a < b < c.

Logic

ready := true
late := false
print(ready and not late, ready or late)
true true

and, or and not can also be written &&, || and !. The right side of and and or only runs when it's needed.

Bits

print(6 & 3, 6 | 3, 6 ^ 3, 1 << 4, 255 >> 4, ~0)
2 7 5 16 15 -1

Order

From first to last:

  1. -x ~x !x
  2. * / %
  3. + -
  4. << >>
  5. &
  6. ^
  7. |
  8. == != < <= > >=
  9. not
  10. and &&
  11. or ||

Use ( ) when in doubt.

When a number doesn't fit

byte b := 250
b += 10
int big := 2147483647
big += 1
print(b, big)
4 -2147483648

A release build wraps around, as shown. A debug build (corfli build -d) stops instead and shows where it happened:

error: the result doesn't fit in int (-2147483648 to 2147483647)
  --> main.cfl:4:1

Dividing by zero always stops the program, in every build.

Chars

Adding a number to a char moves through the letters. Two chars subtract to a number:

c := 'a'
c++
print(c, c + 2, 'z' - 'a')
b d 25