Mochaccino Sprint 1
Share
Explore

icon picker
Features 2.0

Those who can imagine anything, can create the impossible.
Now, let’s look at the new features introduced after the testing process.

Static Typing

Built-In Types

Primitive Types

The primitive types in Mochaccino now include type and fn:
fn<T>
type
dyn
str
num
bool
map<K, V>
arr<E>
void
promise<V>
null

Non-Primitive Types

dt
exc
err
entryPoint
And these types are for debugging:
timeline

Structs

Types of Structs

@abstract

The @abstract struct annotation can be used on top of the @elementary struct annotation only. It gives the elementary struct the ability to behave like a protocol struct by being able to define abstract methods, and preventing instantiation of the struct.

@extensible

The @abstract struct annotation can be used on top of the @elementary struct annotation only. It gives the elementary struct the ability to behave like a protocol struct by being able to define abstract methods, and preventing instantiation of the struct.

@enum

The @enum struct annotation can be used to define enums.

Guarded Keyword

On top of using the gaurded keyword inline, the guarded keyword can be used with braces:
guarded {
var a<num> = num.parse(b);
}
except {
Console.log(e);
}
An object e of type exc is exposed within the scope of the except block.

Props

The static keyword can also be used with props to give static access to fields as well:
struct JSON {
static prop usageCount<num> { ... }
}
Note
Let’s not forget that some keywords like prop and static are only available in elementary structs, and cannot be used with protocol structs.

Static Methods

Elementary structs can have elementary methods and static methods. Elementary methods, as their name suggests, are called on Objects directly. But you can also define static methods in elementary structs:
struct A {
@elementary

static func doStuff()<void> {
...
}
}
So that you can do things like:
A.doStuff();

Struct Polymorphism

Inheritance in Mochaccino is much like in OOP languages, but with a few tweaks, summarised in the table below.
Struct Annotations
0
Annotation
Inheritance
Instantiation
1
@elementary
2
@abstract
3
@extensible
4
@protocol
There are no rows in this table

Implementing Structs

When a struct implements another, it must fill in all abstract members with concrete ones.

Extending Structs

When a struct extends another, it can fill in abstract members with concrete ones, and can also define more abstract members. Only structs marked @abstract can extend other structs.

Debugging

We’ve also decided to introduce a toolbox core library which contains useful tools for debugging such as Timeline and Inspector.

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.