Hi everyone! Iām currently building a custom programming language called Swiq using C++.
Most modern languages rely entirely on standard garbage collection or strict block scoping. When I designed Swiq, I wanted to give developers built-in keywords to control variable state directly.
What makes Swiq unique?
Swiq tracks both the current state and the instantiation state of your data. Here are a few unique features I've built into the memory management system:
- Native Archiving: You can stash a variable away into a hidden memory space and safely pull it back whenever you need it.
- Instant Resetting: Swiq remembers the initial value used when a variable was first created, allowing you to instantly reset it to its default state.
- Explicit Closures: Functions allow explicit variable closure capturing, much like C++ lambdas.
A Quick Look at the Syntax
Here is a quick look at how clean it is to handle variable states, archiving, and resetting in Swiq:
set var score = 100;
// Modify it
set score = 150;
// Need a backup state? Archive it!
archive score;
// Score is now safely stashed away. Bring it back natively:
restore score;
// Want to revert to the very first value?
reset score; // score is now back to 100
And for functions with closures:
set var x = 10;
set var y = 70;
set var z = 25;
// Limited access functions
func myFunction () [x, y] {
log(x);
log(y);
// No access to "z"
}
// Full access functions
func myFunction () [&] {
log(x);
log(y);
log(z);
}
Check out the project!
Swiq is an open-source project and is still actively under development. I built the custom interpreter and Abstract Syntax Tree (AST) completely from scratch in C++.
You can check out the source code, read the documentation, or contribute here:
š github.com/bananakitssu/Swiq
I would love to hear your thoughts on this approach to state management. What features or use cases would you like to see next?
Top comments (1)
There is a new issue with Swiq by the way. If you run:
It would create an error. I need help fixing that.