From 2fbf82f8ab179903b147befad053929622501cb7 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Mon, 18 Dec 2023 01:06:09 -0500 Subject: [PATCH] Add result tuple assert --- src/ludus/prelude.ld | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ludus/prelude.ld b/src/ludus/prelude.ld index 5afd761..ff87149 100644 --- a/src/ludus/prelude.ld +++ b/src/ludus/prelude.ld @@ -903,6 +903,13 @@ fn assert! { else panic! string ("Assert failed: ", msg, " with ", value) } + +fn assert { + "Asserts a condition. Returns a result tuple: `(:ok, value)` if the value is truthy, and `(:err, value)` if it is falsy. Or, give it an error message, and that's what'll be in the error tuple instead." + (value) -> if value then (:ok, value) else (:err, value) + (msg, value) -> if value then (:ok, value) else (:err, msg) +} + &&& Turtle & other graphics & some basic colors @@ -1282,6 +1289,7 @@ ns prelude { unwrap! unwrap_or assert! + assert colors forward!, fd! back!, bk!