jakt
jakt copied to clipboard
Implement must unary operator
This PR adds a must
keyword which acts as a unary operator that corresponds to AK's MUST
macro. I'm not entirely sure if having a separate keyword for this is a good idea however, people I've talked to have stated that it might be better to fold this into the !
operator. I mostly wanted to be consistent with how AK's abstractions for Error
s works (since I am planning on proposing a similar keyword for try
, which would also be a unary operator). What are people's thoughts on this?
I like it.
I just realized I'll need to change this to work with our new way of handling errors (with try catch). I think what would make more sense is to make it something like a must block. Something like:
function main() {
try {
function_that_can_fail1()
function_that_can_fail2()
} catch error {
println("Caught error {}", error.code())
}
must {
function_that_can_fail1()
...
function_that_can_fail2()
...
}
}
Yeah, it could be nice to have must { xyz }
, but let's also support must xyz
. :)
The syntax of the proposed must keyword has been updated. It now can be used in two forms:
- The must unary operator, used like
let x = must foo();
,y + must(x + 3) + must 4
, etc. - Must blocks, which are like try blocks without the corresponding catch:
must {
foo();
bar();
baz();
}
Closed as this is a change for the now-gone Rust-based compiler. Feel free to port your changes to the new compiler, if they're not already added, and open a new PR. :^)