Kaba 0.5.1: Hello, World!
• 3 minutes
Kaba has finally hit all the checklists mentioned in the previous post for the 0.5.x
releases.
What’s new?
Replacing block delimiters and comment symbol (again…)
Blocks are no longer using the do
and end
keywords. They are removed.
Blocks are now using the typical { ... }
style instead, just like the one used in Java or PHP.
Also, the symbol used to create comments is replaced with //
(previous version uses the #
symbol).
// Previously, it was like this:
//
// fn main() do
// # foo
// end
//
fn main() {
// now it's changed to this
}
Read more about this on issue #47 and #48.
Changing the character-case for built-in types
Another breaking change, every built-in types are now converted to lowercase.
For example:
Int
now becomesint
Bool
becomesbool
- And so on…
fn main() {
var x: int = 5;
var y: bool = 10;
}
Read more about this on issue #43.
Changing the syntax for array literals
Yet another breaking change, the syntax for creating array literals is changed.
From:
[1, 2, 3];
To:
[int 1, 2, 3];
// Formal syntax: [T elem1, elem2, ...]
The motivation behind this change is to avoid ambiguities that may arise if we type-infer the array:
// ❓ Should we treat this array as []sbyte, []short,-
// []int, or []long?
[1, 2, 3]
// ❓ How about empty array?
[]
// ✅ By providing the type, we can prevent any
// ambiguities
[int 1, 2, 3]
[int] // the type of an empty array can also be known
Read more about this on issue #50.
Adding support for new numeric types
The int
data type is now splitted into more specific types, each with different size limit:
- Signed byte (
sbyte
), with the size of 1 byte. - Short (
short
), with the size of 2 bytes. - Integer (
int
), with the size of 4 bytes. - Long (
long
), with the size of 8 bytes.
Value assignments to smaller types are also being checked first:
fn main() {
var x = 50;
// ❌ Will trigger compilation error
var y: sbyte = 999;
}
Aside from integers, floating-point numbers also have a new default type: the double
type (float
still exist, by the way).
fn main() {
var x = 5.0; // defaults to double
var y: float = 10.5;
}
You can read more about those specifications in the docs.
Adding support for character and string types
Big improvements of this release: the new char
and string
types🎉
Example usage for char
type:
fn main() {
// Denoted by single-quote characters
debug 'a';
// It also supports some escape-characters
debug '\n';
debug '\x41';
}
As for the string
type:
fn main() {
// Denoted by double-quote characters
debug "Hello, World!";
// It also supports escape-characters, just
// like the `char` type
debug "Hello,\tWorld!"
}
What’s next?
My next goal is to add support for struct
data type and also add string interpolation capabilities, while some of the previous targets are postponed (type casting and IR codegen).
Thanks for reading, see you next time!👋
Baca Juga
Kaba 0.4.0: Bringing Array to the Equation
Kaba introduces array alongside some other features in version 0.4.0. Read more about all the new features in this article.
• 3 minutes