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

First parse examples

Let's start with some simple examples, where we have a product code that starts with the letter combination XY, followed by a digit, which we defined as a bitset digit in the previous section, for example, "XY6". We can parse this input with the rule block ["XY" digit]:

;-- see Chapter08/how-parse-works.red:parse "XY6" ["XY" digit]      ;== true

This works as follows. Look inside "XY6" from left to right, find a "XY", if found, then find one digit. If this is found and we are at the end of the input, return true. But in the code "XY67" there are two digits. The end of the input was not reached, and parse returns false:

parse "XY67" ["XY" digit]    ;== false

We can make it match by specifying the number of digits, like this: ...

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