Replace ENSURE with THE ?

I make frequent use of something called ENSURE, which lets you check that something is the type you think it is. It passes it through if it is, and errors if not:

>> ensure integer! 5
== 5

>> ensure integer! "not an integer"
** Error: ENSURE failed with argument of type text!

The error message could be better, but you get the idea.

It has a counter part called NON:

>> non integer! 5 
** Error: NON failed with argument of type integer!

>> non integer! "not an integer"
== "not an integer"

Lisp calls its ENSURE operator "THE"

It's maybe a little bit less obvious, but it does save on typing:

>> the integer! 5
== 5

>> the integer! "not an integer"
** Error: THE failed with argument of type text!

It makes a bit more sense when you use it with a single type than when you use it with more than one:

>> the [integer! text!] 5
== 5

>> the [integer! text!] "not an integer"
== "not an integer"

Worth changing?

Being short and 3-lettered makes it kind of a better complement to NON. They read pretty well:

>> value: 5

>> append [1 2 3 4] the integer! value
== [1 2 3 4 5]

>> append [1 2 3 4] non null value
== [1 2 3 4 5]

I'm leaning toward thinking this might be worth the change. Though ENSURE isn't really needed for anything else. Maybe they could be synonyms, and if you wanted to retake the short THE for something else you could.

1 Like

From the perspective of a newbie, I probably wouldn't connect the meaning of THE to what I think is the more intuitively/explicitly named ENSURE. THE is brief, but I think it strays into English grammar but without the added benefit of clarity.

Anyway, that's my bargain-basement $.02. Whether or not THE has precedence in LISPers (reminds me more of Logo) well...

Ensure sounds less likely to confuse newbies

THATS integer! 5

;extra chars to make post long enough

I consulted my thesaurus and I think that ensure is still the best option here. check or verify are possibilities as well, but ensure is clearer. I did wonder about make sure but that left me wondering what a sure would do :slight_smile: