The Cool New Repurposing of WHILE in PARSE

Historical Redbol PARSE had some cognitive dissonance over its "looping constructs".

One weird point was that WHILE was an arity-1 construct...a peculiar variant of a "looping ANY" which dropped the requirement of a need to make progress. :confused:

Just as ANY could be improved by making it do something more "obvious", I think the obvious solution for WHILE is also the better one:

So now, default PARSE has WHILE and it's arity-2 !

These two things are synonyms:

 while rule1 rule2   <=>  opt some [rule1 rule2]

One very common application is WHILE [NOT <END>] [...]

This is such a clear case it's bizarre that no one seemed to go to bat for it before.

It would make it cleaner to pair up code in a GROUP! with a rule:

GROUP! rules always run their side effect and succeed. So:

opt some [rule (code to run on each match)]

Could instead be written as:

while rule (code to run on each match)

I would use this frequently!

It helps pscyhologically divide a process into two parts: trigger and response

You can of course write things as:

opt some [
     thing1 thing2 [
        thing3 thing4
     |  thing5 thing6
     ]
]

Or:

opt some [thing1 thing2 [
    thing3 thing4
        |
   thing5 thing6
]]

But I think the WHILE structuring into a control half and response half helps you see this better:

while [thing1 thing2] [
    thing3 thing4
        |
    thing5 thing6
]
3 Likes

I like WHILE as described here and the improved consistency of ANY and ALL.

1 Like