Comments on: Recursion Safe PARSE Rules
REBOL Technologies

Comments on: 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

Comments:

Gregg Irwin
16-Sep-2010 10:21:11
Ladislav pointed out that it could be more efficient, and more elegant, but it will definitely be useful. It's worth considering for standard inclusion IMO.

I would still love to see RT, or some REBOL gurus do some sample toy language implementations that show off parse and act as primers.

Ladislav
16-Sep-2010 16:11:54
http://www.rebol.org/view-script.r?script=use-rule.r updated. Changes: now it implements both USE-RULE variants as described in http://www.rebol.net/wiki/Parse_Project .
Ladislav
16-Sep-2010 16:13:48
Regarding the "toy language" note. How about the http://www.fm.tul.cz/~ladislav/rebol/evaluate.r ?
Maarten
19-Sep-2010 23:19:18
The idea looks a bit like what we did with proper tail recursion some years ago, using 'use as a a closure to create a "hidden stack" frame. Nice use case.

Post a Comment:

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

Name:

Blog id:

CS-0486


Comment:


 Note: HTML tags allowed for: b i u li ol ul font 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.

Updated 22-Oct-2017   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code