Reacting to Definitional Errors: CURTAIL

Here's a simple REFRAMER called CURTAIL:

curtail: reframer function [frame [frame!]] [
    return do frame except e -> [
        if e.id == 'need-non-null [return void]
        raise e
    ]
]

If you don't remember what reframers do, they just have access to a function call before you run it. Here we are looking for the function we're running to give us a NEED-NON-NULL error.

But we're not looking for just any NEED-NON-NULL error that might go by. We're only interested in ones that are coming out of the call we're processing. If that happens, we just vaporize the expression.

>> compose [(null)]
** Script Error: non-NULL value required (see MAYBE, TRY, REIFY)

>> curtail compose [(null)]  ; will give back void

You can see something like this simplifying null checks:

>> ver: 1.2.3
>> date: null

>> print [curtail spaced ["Version:" ver] curtail spaced ["Date:" date]]
Version: 1.2.3

But like I said, it's not just any NEED-NON-NULL...

>> a: 1 b: null c: 3
>> get-ver: func [] [to tuple! reduce [a b c]]

>> print [curtail spaced ["Version:" get-ver] curtail spaced ["Date:" date]]
** Script Error: non-NULL value required (see MAYBE, TRY, REIFY)