REBOL 3.0

Comments on: PARSE: any, some, loop with break and reject

Carl Sassenrath, CTO
REBOL Technologies
14-Oct-2009 20:01 GMT

Article #0273
Main page || Index || Prior Article [0272] || Next Article [0274] || 8 Comments || Send feedback

Here's the implementation planned for A90:

 anyattempts rule until it fails or the input did not change. Always succeeds.
 somethe same as any except requires at least one match to succeed.
 whilethe same as any except does not care if the input changed. The while keyword is used for special cases where iterations may not modify the input position, but we want the loop to continue.
 breakbreaks out of any of the above loops, always indicating success.
 rejectbreaks out of any of the above loops, always indicating failure.

Note that both break and reject stop the loop iteration immediately. Any pending copy or set actions are not done.

BREAK or ACCEPT?

The one remaining issue might be: should we rename break to accept or just leave it as is?

The main reason to rename it is to better match reject.

The reason not to rename it is that people already know about break.

Updated

The while keyword is used instead of loop. The rationale is that a while loop continues while the condition is true. So, while is closer in meaning than loop.

8 Comments

Comments:

-pekr-
14-Oct-2009 16:48:42
hmm, so out of all votes you chosed 'loop name noone voted for :-)
Carl Sassenrath
14-Oct-2009 17:01:25
I considered each name carefully:

  • every - a great word, but sounds like it does every rule, which is not true. (But, maybe we can use this instead of OF rule in 3.1).
  • always - I liked it, but BrianH thought it was ambiguous. True.
  • cycle - Pekr (you) thought it too much like recycle. Not really a problem, but it does seem a bit out there (e.g. CPU cycles.)
  • forever - not really true - the loop continues until no rule matches. So, it is not forever.

I realized that this loop is actually more like while, but in the form of REBOL's until (with a single block). That is, it loops while the block is true (meaning something matched) and exits when the block is false (nothing matched.)

-pekr-
14-Oct-2009 17:24:36
OK, the explanation sounds good. I liked 'every later, as it kind of complements sounding of words like 'any, 'some, I wonder if we would find usage for 'all.

As for 'every instead of 'of? 'of is "one of following rules", so I don't understand, how 'every name is better than 'of for such purpose?

Brian Hawley
14-Oct-2009 19:29:30
I like while, good choice.

Does break break out of the nearest enclosing any, some or while loops, or out of any iteration including the implicit 1 before every rule?

Breaking out of every iteration as break does in R2 has been problematic, especially since it forces you to physically put the break at the same nesting level as the outermost rule block that it is breaking from. This limits your algorithmic options a bit.

If you are changing break to break out of any, some or while (as I would prefer), then it would be a good idea to rename it to accept to signify that R2 code that uses break might need some going over to make sure it still works. And you are right that it matches reject better, as long as its breaking behavior is the same. If you are keeping the old behavior, you can keep the old name.

Kaj
15-Oct-2009 7:17:07
A90 seems to break the SECURE dialect.
Ben
15-Oct-2009 11:42:36
+1 for accept
Hostile Fork
15-Oct-2009 17:06:16
+1 for accept (to pair with reject)

As an alternative, return true and return false would be okay. But break just doesn't suggest what will be handed back to the caller (I would have assumed false over true actually).

Brian Hawley
16-Oct-2009 1:14:39
Fork, the proposed break (or better, accept) doesn't return anything to the caller, it just breaks out of an iterated rule (all rules are implicitly iterated, apparently) and tells PARSE that the rule was successful.

Returning something to the caller is what return does.

Post a Comment:

You can post a comment here. Keep it on-topic.

Name:

Blog id:

R3-0273


Comment:


 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote
 
 

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

REBOL 3.0
Updated 24-Apr-2024 - Edit - Copyright REBOL Technologies - REBOL.net