TRIPWIRE in The Wild

If you access an unset variable, you don't get a lot of information back:

>> state: ~

>> state
** Script Error: state is ~ antiform
** See ^(...) and GET/ANY

But with antiform tags, you can embed a message into the unset variable:

>> state: ~<INITIALIZE-STATE hasn't been called yet>~

>> state
** Script Error: state is ~<INITIALIZE-STATE hasn't been called yet>~ antiform
** See ^(...) and GET/ANY

This new concept is called a TRIPWIRE.

DEFAULT reacts to it, considering the variable to be "vacant"

>> vacancy? get/any $state
== ~okay~  ; anti

>> state: default [10 + 20]
== 30

>> state
== 30

Can Be Better Than A Meandering Comment!

A comment won't direct people to the relevant issue at runtime. But a well-chosen tripwire can.

Compare:

; !!! UPARSE is not available in SYS because it is higher level.  We hack it
; up so that when %uparse.r runs it pokes itself into sys.util/parse
;
parse: ~

With:

parse: ~<higher-level %uparse.r hasn't set SYS.UTIL/PARSE yet>~

Much better! Gives you the information you need, when you need it!

(Note: I was inspired to this concept by a style of usage @rgchris had in his scripts, using TAG!s to provide guidance for what was supposed to be filled into certain slots. I just wanted to give that some teeth, to know that the variable was conceptually unset.)

2 Likes