Sol is an imperative, statically-typed language designed as a tool for learning how to program. It is simple, in that it has few language features and can thus be learned quickly. It is obvious, in that it should be clear from reading the source code of an application what instructions the computer will execute.
Many common programming language features that allow programs to be more expressive were intentionally left out. See non-features for more details.
function main() {
print("Hello, world!");
}
function main() {
constant answer = 42;
constant message = "The secret is " + String(42);
print(message);
}
function maxNumber(numbers Number[]) -> Number {
variable max = 0;
for index, number in numbers {
if index == 0 {
max = number;
continue;
}
if number > max {
max = number;
}
}
return max;
}
function main() {
variable allNumbers = Number[1, 7, 3];
variable bigNumber = maxNumber(allNumbers);
print("The biggest number is " + String(bigNumber)); # The biggest number is 7
}
function fibonacci(num Number) -> Number {
if (n <= 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
What should be of more note to existing programmers is not what features Sol implements, but rather those it does not. What follows is a non-comprehensive list, along with the rationale for omitting it.
While Sol allows constants to be defined globally, it does not have global variables. Variables only exist within the scope of a function, and to share them you must either pass their value or a pointer to them via function arguments.
Keyword | Description | Implemented? |
---|---|---|
variable |
A mutable variable | [x] |
constant |
An immutable variable | [ ] |
function |
A custom function. | [x] |
Type | Example | Description | Implemented? |
---|---|---|---|
String | "Hello, world!" |
ASCII, immutable string | [x] |
Number | 12.3 |
Floating point number (currently 32-bit) | [x] |
boolean |
variable shouldUpdate = false; |
Either true or false |
[x] |
Type | Example | Description | Implemented? |
---|---|---|---|
List | String["A", "b", "Hello, world!"] |
An untyped, growable list of objects | [x] |
Map | Number{"age": 36} |
Hash map from String to a single type. |
[ ] |
Keyword | Example | Implemented? |
---|---|---|
if |
if check() {} |
[x] |
for & in |
for idx, el in elementList {} |
[x] |
Function Name | Description | Implemented? |
---|---|---|
run(String[]) |
Run a subprocess. | [x] |
Function Name | Description | Implemented? |
---|---|---|
print(String) |
Print a String to STDOUT |
[x] |
printError(String) |
Print a String to STDERR |
[ ] |