Difference between BREAK and REJECT in PARSE

Both in Rebol and Red , there are two PARSE keywords: breakand reject, which have similar behavior: breaking out of the correspondence loop (for example, any, some, while), the difference is that it breakalways indicates success , but rejectindicates failure . I know what this means literally, but cannot find a suitable scenario in which which of the two keywords should be used.

blk: [ 1 #[none] 2 #[none] #[none] 4 5 6 #[none] ]
count: 0
result: parse blk [
    any [ 
            remove none! insert 2 
            if ((count: count + 1) >= 2) break
            | 
            skip
    ]
]
probe blk          ;will get [1 0 2 0 none 4 5 6 none]
probe result       ;will get false
probe count        ;will get 2

In the above code break, either or rejectwill produce the same result.

So can anyone show me what is the difference between these two keywords?

+4
1

, break, , .

>> parse "aaabbb"  [ some [ "a" break ] to end]
== true

"" , . .

>> parse "aaabbb"  [ some [ "a" reject ] to end]
== false

, "a" , .

. Carl blog.

+3

Source: https://habr.com/ru/post/1538814/


All Articles