Logic

The basics of Imba

Imba is an indentation based language. If you have written any Ruby or Python then a lot of the syntax will feel familiar. Even though the syntax and semantics of Imba is much more related to Ruby than JavaScript, it does compile down to plain JavaScript, and is fully compatible with any existing JavaScript libraries. Imba does not extend any native types from JavaScript. Arrays are arrays, strings are strings, numbers are numbers, classes are constructors with prototypes and so forth.

Interoperability

All the fundamental types are the same as in JavaScript, so for documentation about available methods see MDN Object, Function, String, Number, RegExp, Array, Date, Math.

Strings

var single = 'single quotes'
var double = "double quotes"
var interpolation = "string has {double}"

Numbers

var integer = 42
var float = 42.10

Objects

var object = {name: 'Imba', type: 'Language'}

If you can't stand the curly braces then indentation will also work

var object =
name: 'Imba'
type: 'Language'

Arrays

var array = [1,2,3,4,5]

Regular Expression

var regex = /number is (\d+)/

Loops

for num in [1,2,3]
num
for own key, value of object
value

Functions

def hello name="world"
return "Hello {name}"
console.log hello!
console.log hello('you')

Classes

class Dog
def constructor name
name = name
def bark
"woof woof"

Operators

var item
item = 100 # set value of item
item ||= 100 # set if value is falsy
item &&= 100 # set if value is already truthy
item ?= 100 # set if value is null or undefined
# comparators
item == 10 # check
item === 10 # strictly equal
item != 10 # not equal
item !== item # strictly not equal
item > 10 # greater than
item < 10 # less than
item >= 10 # greater than or equal
item <= 10 # less than or equal

Bitwise Operations

a & b # Bitwise AND
a | b # Bitwise OR
a ^ b # Bitwise XOR
~ a # Bitwise NOT
a << b # Left shift
a >> b # Sign-propagating right shift
a >>> b # Zero-fill right shift

Edit on GitHub