Skip to content

Commit

Permalink
Add MUST as native for NON NULL behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
hostilefork committed Jun 20, 2021
1 parent aaea7c0 commit b185ba5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/n-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,27 @@ REBNATIVE(match_p)
}


//
// must: native [
//
// {Ensure that the argument is not NULL}
//
// return: "Same as input value if non-NULL"
// [any-value!]
// value [<opt> any-value!]
// ]
//
REBNATIVE(must) // `must x` is a faster synonym for `non null x`
{
INCLUDE_PARAMS_OF_MUST;

if (IS_NULLED(ARG(value)))
fail ("MUST requires argument to not be NULL");

RETURN (ARG(value));
}


//
// all: native [
//
Expand Down
7 changes: 7 additions & 0 deletions tests/control/match.test.reb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@
]


; MUST is an optimized form of NON NULL
[
("bc" = must find "abc" "b")
(error? trap [must find "abc" "q"])
]


; MATCH was an early function for trying a REFRAMER-like capacity for
; building a frame of an invocation, stealing its first argument, and then
; returning that in the case of a match. But now that REFRAMER exists,
Expand Down

0 comments on commit b185ba5

Please sign in to comment.