Note
This language is still under active development! Some features may not be set in stone yet and new features are still being added. This project will enter the alpha phase once all milestones are met.
An experimental compiled programming language focused on making the syntax as compact as possible without sacrificing readability.
\ this is a comment!
\ this imports `cout` from the standard library...
+std:cout
myConst :: "I'm a const variable"
myVar :- "I'm an immutable variable"
myMutable := "I'm a mutable variable"
\ adding an explicit type works too!
mySpecified: String = "I'm also a mutable variable"
\\ this is a multi-line doc-comment to be utilized by IDEs.
\\ no parameters, returns a string.
helloWorld |-> String
"Hello world!"
\\ 2 parameters, returns a string.
greet | String String -> String
theirName myName:
"Hello {theirName}! I'm {myName}."
\\ has a parameter, returns nothing.
\\ prints greeting to console based on input.
greetFriend | String
"Ferris":
cout <| greet("Ferris" "a crustacean too")
"Octocat":
cout <| greet("Octocat" "in a repo")
creature:
cout << "Unknown friend: " <| creature
Tip
Functions are capable of pattern matching, in a style similar to Haskell.
<functionName> | [argTypes...] [-> returnTypes...]
<patterns...> [<- guard]:
<returnValues...>
It may also be helpful to read <- as if, since it's also used in ternary operations:
response := "ready" <- is_ready ; "not yet"
Here are some more advanced examples:
\\ a scenario where pattern matching is more useful!
factorial | Int -> Int
n <- n < 2: 1
n: n * factorial(n-1)
\\ tail-recursive version.
factorialTail | Int Int -> Int
n total <- n < 2: total
n total: factorialTail(n-1 total*n)
\\ a simple struct.
Item =
name String
amount Int
\\ now with generic type `T`!
Person<T> =
name String
age Int
items T[2]
addItem | T
item: .items << item
getItems |-> *T[2]
*.items
\\ a simple trait.
Animal:
growUp | Int -> Int
\\ implement the Animal trait for Person struct...
Person<T> => Animal
growUp | Int -> Int
years:
.age += years
.age
Important
To actually run some code in Soulite, you would want a main function:
main | [String]
[]: cout <| "Usage: <programName> [-h] <command> <..args>"
["fac" n]: cout <| factorialTail(n.parse().unwrap() 1)
["people"]:
john := Person("John" 21 ["car keys" "credit card"])
john.growUp(3)
cout <| john.age \ should print "24"
["-h" "fac"]:
cout <| "Calculates the factorial.\nUsage: <exe_name> fac <Integer>"
args:
cout <| "invalid input `{args.join(" ")}`"
main([])
Check out the wiki for an in-depth exploration!
$\color{green}\text{Variables}$
$\color{green}\text{Mutable}$ $\color{green}\text{Immutable}$ $\color{green}\text{Static}$ $\color{green}\text{Const}$
$\color{green}\text{Comments}$
$\color{green}\text{Single line}$ $\color{green}\text{Multi line}$
$\color{green}\text{Functions}$
$\color{green}\text{Parameter matching}$
$\color{green}\text{Pattern matching}$
$\color{green}\text{Literals}$ $\color{green}\text{Variables}$ $\color{green}\text{Wildcards}$ $\color{green}\text{Guards}$ $\color{green}\text{Generic types}$
$\color{green}\text{Structs}$
$\color{green}\text{Fields}$ $\color{green}\text{Generic types}$
$\color{green}\text{Methods}$
$\color{green}\text{Generic types}$ $\color{green}\text{Self field reference}$
$\color{green}\text{Traits}$
$\color{green}\text{Method declaration}$ $\color{green}\text{Generic types}$
$\color{green}\text{Struct implements}$
$\color{green}\text{Generic types}$ $\color{green}\text{Self field reference}$
$\color{grey}\text{Expressions}$
$\color{green}\text{Ternary conditional}$ $\color{green}\text{Anonymous functions}$ $\color{green}\text{Option data type}$ $\color{green}\text{Result data type}$
$\text{Data structures}$
$\color{green}\text{Arrays}$ $\color{green}\text{Lists}$ $\text{Tuples}$ $\text{HashSets}$ $\text{HashMaps}$
$\text{Loops}$
$\text{For loop}$ $\text{While loop}$ $\text{Infinite loop}$
$\color{grey}\text{Toolchain}$
$\texttt{soulite}—\text{completion of the milestones above}$ $\texttt{soulforge}—\text{package manager and build tool}$ $\texttt{soulfmt}—\text{code formatter}$ $\texttt{soulstd}—\text{standard library}$ $\texttt{souldocs}—\text{local docs webpage generator}$ $\texttt{soulsight}—\text{language server}$ $\texttt{soulsrc}—\text{local source code of standard library}$