-
Notifications
You must be signed in to change notification settings - Fork 1
Hello World
This is a language designed to be friendly to use, while also readily extensible for other developers to add their own DSL features.
Let's dive in!
In MScript v1, printing is done via the print keyword:
print "Hello World!"This method of printing will output to stdout and is buffered. Quick, dirty and simple—the value for a print can be of any type.
Note: print is not a function. If you attempt to call it as such, ie. print("goodnight"), your code will not compile as print has not been defined.
The print keyword is deprecated starting in MScript v2. Instead, use the standard library's print method. Despite its deprecation, print will be used throughout the documentation for brevity.
import std
std.print("Hello World!")
# or, import it directly!
import print from std
print(42)
assert print is std.print # trueThis function takes an argument that satisfies the interface ToString, defined in the standard library as:
export type ToString interface {
fn to_str(self) -> str
}Interfaces will be covered more in depth in a future chapter. For a beginner's purposes, just know that every type that the languages provides you out of the box can be printed.