A data-oriented programming language
This language is a small concept that doubles as my foray into Haskell & its Megaparsec library. The concept is built from multiple (radical) ideas I realized while working in Lua, Rust, Nix, and a tad bit of Scala I tried while contributing to newsboat (a popular RSS feed reader).
- Loops are often just a compensation mechanism for undescribed state machines that could have otherwise formed an effective loop between different states, rather than relying on a big loop with a "TODO list" of things (states).
- String is often just an "excuse type" for an unparsed chunk of text, be it a URL, email, password with requirements, or even English.
- A surprisingly rich amount of data can be described using only hierarchical tables (called modules in
lunetta)
Hello, World!
module Program : Entrypoint
io.out: "Hello, World!" Hello, World!
Hello, World!
If you look very closely, we aren't actually calling an out function within an io namespace, we are setting an out value within an io namespace and returning it, effectively:
return {
io = {
out = "Hello, World!"
}
}Before continuing, I'd like to mention that while it's very much a Work In Progress, you can give it a try yourself in this web preview:
The idea is that the runtime (or in the future, a virtual runtime in the compiler that simplifies the code) will take this io table you've returned, pass it to
an io module registered with it, and the io module updates.
Okay, but you want to read inputs too:
module Grade
>= 95: "A+"
.. 85 94: "A"
.. 61 84: "B"
.. 31 60: "C"
.. 16 30: "D"
.. 5 15: "F"
module Program : Entrypoint io
io.out: Grade io.in no output — this program reads io.in
> 75
B
A few things to notice:
- Lisp inspired operators
- Operators-as-index
So:
flowchart LR
Wait --> InputRecv
InputRecv[Input Updated] --> Entrypoint{Does the module use this?}
Entrypoint -- Yes --> CallModule[Call Module]
Entrypoint -- No --> DoNothing[Do Nothing]
CallModule --> ReturnOutputs[Return Outputs]
ReturnOutputs --> Wait
The Advanced Stuff
From here on out, I'll describe some theoretical ideas that the compiler can't yet compute (and that the syntax highlighter isn't yet familiar with :/).
syntax Filename
# A "place" is either dots (relative) or a directory/file name
place: [.]+:relative=true | Any:directory_name
# You must have a single place to start with (referenced using a #)
# But you can have multiple places
#place [/ #place]+ . Any:extension
module Upload with std
id: std.UUID
filename: Filename
status: -> State # Upload.State
-> Pending # Upload.State.Pending
queued_at: Instant
-> InProgress
bytes_sent: u64
total_bytes: u64
started_at: Instant
|-> Complete
url: String
checksum: [u8; 32]
|-> Failed
error: Upload.Error
attempts: u32
| && error.retryable (< attempts 5): InProgressThis syntax keyword essentially functions as an alternative to string. The plan is to entirely phase out string and replace it with syntax after the first few versions of the compiler.
This means that when a module accepts a Filename, it can be type-checked both at compile time if we know the filename (or can prove certain things true or false about the runtime value),
or at runtime. This means that your validation gets better on each compiler version as the compiler learns specific cases and does the heavy lifting (e.g. if you have a runtime value we don't know, but the compiler knows for sure that you put a "^" character in it and pass it as a filename, that it wouldn't typecheck).
Next, is the submodule system described in module Upload. -> [Identifier] is just module definition shorthand. |-> [Identifier] says "this is one of many possible module paths".
The very last line is a self-setter due to the |, it functions as a sort of conditional.
This effectively forms a loop:
flowchart LR
Pending --> InProgress
InProgress -- Success --> Complete
InProgress -- Failure --> Failed
Failed -- Retryable? --> InProgress
You might wonder though that this syntax can only go so far, at some point you're going to need complex imperative logic. Which is why operators are a meta-programming feature and not a language feature.
syntax Number
[ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ]+
-> .. : Number.Range(Self:low Self:high)
-> >= : Number.GreaterThanOrEqualTo(Self:first Self:second)And even the base operators have been a lie:
syntax Program : Entrypoint
-> && : Program.And(Self:first Self:second)
...Soon
I have more ideas for this language, that I hope to write in a future blog post, as I get the compiler up to speed. Primarily a full working program example, as well as a church numeral implementation, and my thoughts on current compilation and why I dislike std-level abstractions in current programming languages (where in the compiler directly has a unique line of communication with the standard library that creates seemingly unimportant type gaps in the program). Stay tuned for a suspiciously string-less compiler coming soon to a blog post near you (and std/acc).