Skip to Content
Learn Red ? Fundamentals of Red
book

Learn Red ? Fundamentals of Red

by Ivo Balbaert
May 2018
Beginner content levelBeginner
252 pages
6h 19m
English
Packt Publishing
Content preview from Learn Red ? Fundamentals of Red

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

How I Built a Personal Board of Directors With GenAI

How I Built a Personal Board of Directors With GenAI

Vipin Gupta
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally
Why AI Demands a New Breed of Leaders

Why AI Demands a New Breed of Leaders

Faisal Hoque, Thomas Davenport, Erik Nelson

Publisher Resources

ISBN: 9781789130706Supplemental Content