Ribbit

→ javascript dialect

Ribbit is an odd javascript library.
It provides some advantages (and disadvantages) over plain javascript.

Type System


Ribbit has its own type system.

Type Checking

["Joe", "Flora"].is(List) == true

Type Conversion

"24".as(Number) == 24

Type Assertion

let age  = Int(24)
let name = String(24) //Error: Type Mismatch

Custom Types

let UpperCase = new Type ({
	base:    Text,
	convert: text => text.toUpperCase(),
})

"HELLO".is(UpperCase) == true

Static Typing

let scores = new Int[_]
scores.push(4)
scores.push(7)
scores.push(5.2) //Type Error!

Property Editor


Define properties easily.

Getter

luke.name    = "Luke"
luke.surname = "Wilson"
luke._.fullname.get = o=> `${luke.name} ${luke.surname}`

luke.fullname == "Luke Wilson"

Static Typing

luke._.name.type = Text
luke.name = 24 //Type Error!

Full Definition

player._.health = {
	value: 10,
	set: (v) => {
		player._.health.value = v
		if (v <= 0) print("You died!")
	},
}

Pattern Matching


Use pattern matching to save time and space.

Match

input.match (
	Text,       "It's some text",
	"Luke",     "It's my name",
	[Num, Num], "It's a list of two numbers",
	_,          "It's something else",
)

Matcher Function

const fibonnaci = matcher (
	[0],   0,
	[1],   1,
	[Num], n => fibonnaci(n-1) + fibonacci(n-2),
)

Function Syntax


Ribbit gives you more options for how to work with functions.
Some might seem more useful than others.

This

You can use arrow notation to make a function-scoped function.

luke.grow = f(self => self.age++)

Bracketless

You can call functions without brackets.

print.x= "Hello world!"

friends.o.forEach.x= friend => print(`Hello ${friend}`)

friends.o.for.o(10).x= friend => print (`You're in my top 10 friends!`)

Classes


Use Ribbit's type system to extend and/or create classes.

Extend

Number.O.multiply = f((self, num) => self * num)
(3).multiply(4) == 12

Even.O._.half.get = f(self => self / 2)
(4).half == 2
(5).half == undefined

Create

const Person = new Class ({
	name: String,
	age:  Number,
	grow(){ this.age++ },
})

let luke = new Person ("Luke", 24)
luke.grow()