THIS LESSON IS ACTIVELY BEING WRITTEN
Contents
Intro
Let's deal with it! It's not complicated if you ever have been programming something.
The StaLang is in development
StaLang Docs is in drvelopment
Builtin Values
In StaLang there are 4 builtin values:
True & False
Nil
Nil value is an absence of any value. Funny 😆.
In StaLang nil is highly similar to Nil concept in other languages like Go, Swift, and etc.
Nil is handled with a bench of operators (more info on operators is here).
Let's consider the following example:
/*
we define a value `email` which can be a string or nil.
*/
data email: str? = later;
fetch(_ userId: int) -> str? |> Server::fetch(userId);
const userId: int = 4;
email = fetch userId ?? "no email"
fetch is a labeled function. More info on functions is here.
None
None is an absence of any value. What's the difference between none and nil?
None will not raise an error because any value in StaLang can be none.
When you define a new data without assigning to it a value, the StaLang interpreter automatically assigns to it a none value, not nil.
Imagine you fetch user data from a server.
core Net;
const url: str = "https://localhost:8000";
const userId: int = 1;
data userName: str;
data userAge: str;
data userGender: str;
data userModel = Net::Server(url).fetch userId ?? "UserId is not valid";
userName = userModel::userName;
userAge = userModel::userAge;
userGender = userModel::userGender;
The example is hypothetical, nevertheless good for understanding difference between nil and none.
- The data
userNamewill has a string value"user", because in the database the user has an assigned name. - The data
userEmailwill have anonevalue, because the user has no assigneduserEmail. - The data
userGenderwill have a value nil and the NilError will be raised, because theuserModelhas not the propertyuserGender, therefore we can't get a value, assigned to it.
Later
Later is a value, not a keyword, which means that you are a lazy programmer and don't want to assign a value right now. When you will run your code, the interpreter will execute a Lazy Warning.
Values' Types
Value types are basic types of data, such as string, numbers, etc.
In StaLang there are following value types.
- String
str - Integer
int - Float
float - Bool
bool - Number
num - Binary
bin - Hexadecimal
hex - Any
any
Comparison with other languages:
| Type | StaLang | Swift | Rust | TypeScript | Go | Python |
|---|---|---|---|---|---|---|
| Integer | int | Int | int | |||
| Number | num | - | number | |||
| String | str | String | str | string | ||
| Character | - | Character | ||||
| Binary | ||||||
| Hexadecimal | ||||||
| Float | ||||||
| Double | ||||||
| Dynamic / Auto | ||||||
| Any |
In StaLang there is no character type. Character methods are implicated to the string type.
Example code:
data x1: int = 5;
data x2: float = 5.4;
data x3: str = "5";
data x4: bool = 5 > 5.4; // false
data x5: bin = ;
data x6: hex = 5;
data x7:
Data types
COMMING SOON
Final thoughts
COMMING SOON
Links
GitHub source code: StaLang
GutHub IDE for macOS: StaLang IDE
GitHub Docs: StaLang Docs
Ask any questions in the comments below!
Top comments (0)