From 30d39378c721aa6506c5aa038f6da9bf98cb1527 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 11 Sep 2024 12:39:56 -0400 Subject: Optional C Strings --- test/optionals.tm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/optionals.tm') diff --git a/test/optionals.tm b/test/optionals.tm index a721deaa..521bba51 100644 --- a/test/optionals.tm +++ b/test/optionals.tm @@ -49,6 +49,12 @@ func maybe_lambda(should_i:Bool)-> func()?: else: return !func() +func maybe_c_string(should_i:Bool)->CString?: + if should_i: + return ("hi":as_c_string())? + else: + return !CString + func main(): >> 5? = 5? : Int? @@ -162,6 +168,19 @@ func main(): fail("Truthy: $nope") else: !! Falsey: $nope + do: + !! ... + !! C Strings: + >> yep := maybe_c_string(yes) + = CString("hi")? + >> nope := maybe_c_string(no) + = !CString + >> if yep: >> yep + else: fail("Falsey: $yep") + >> if nope: + fail("Truthy: $nope") + else: !! Falsey: $nope + if yep := maybe_int(yes): >> yep = 123 : Int -- cgit v1.2.3