Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-10-28 22:13:49 -05:00
commit 05756094ac
706 files changed
+135430

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
# An `ensures` names what the function returns, and `old` within it is what an
# expression was where the `ensures` was reached.
import std::io;
struct wallet { var balance: u64; }
def withdraw(from: &mut wallet, amount: u64): u64 {
expects(amount <= from.balance, "A wallet gives no more than it holds.");
ensures(left: left == old(from.balance) - amount);
from.balance -= amount;
return from.balance;
}
def withdraw_wrongly(from: &mut wallet, amount: u64): u64 {
ensures(left: left == old(from.balance) - amount);
from.balance -= amount;
return from.balance + 1;
}
def main(): void {
var held := wallet { balance = 10 };
io::println($"{withdraw(&mut held, 3)}");
io::println($"{withdraw_wrongly(&mut held, 3)}");
}