Parsing blocks and code

Parsing is not only used for string data, it can also be applied on blocks, including Red code. Let's concentrate here on what is specific for blocks, particularly the use of words and types in the match rules.

The following parse statement returns true:

parse ["x"] ["z" | "x" | "y"] ;== true, but this statement  parse [x] [z | x | y]  gives us a  Script Error: PARSE - invalid rule or usage of rule: z. Why is this? Red doesn't know the types of x, y, and z; it has to consider them as words, and when they don't have a value Red returns an error. 

However, we can make this work like this:

parse [x] ['z | 'x | 'y] ;== true

By indicating with ' that x, y, and z are words, Red can make sense of the statement.

=> Now answer ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.