REBOL Technologies

Recursion Safe PARSE Rules

Carl Sassenrath, CTO
REBOL Technologies
14-Sep-2010 21:02 GMT

Article #0486
Main page || Index || Prior Article [0485] || Next Article [0487] || 4 Comments || Send feedback

Ladislav has created a useful function, an idiom, for recursive (and someday threaded) PARSE rules.

This function is useful because PARSE rules often store data in variables which, depending on how you handle them, can be overwritten by rule recursion. (Which is done often in parsing.)

Ladislav points out an example rule like this:

rule: [
    "b" (print 1) |
    a: "a" rule "a" b: (print subtract index? b index? a)
]

Here, because the a: is set before the re-entry into rule, it will be overwritten.

Ladislav's solution is called use-rules (as in the use function for rules). It is posted on REBOL.org at use-rule function. It includes a simple example.

A handy idiom.

4 Comments

Updated 12-Nov-2024   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code