Checking block structures
06-Jul-2007 18:43 Filed in: REBOL
Beginners
Do you have a large block of data that you want to
check the structure of?
PARSE is a good way to do that, since it returns TRUE if it can parse the entire block properly. PARSE happens also to be very fast.
Our data should be a block of blocks:
data-block: [
[1 2 3]
[4 5 6]
[7 8 9]
]
So you can simply check that each entry is a block:
>> parse data-block [any block!]
== true
Let's sabotage our data block:
data-block: [
[1 2 3]
none ; oops!
[4 5 6]
[7 8 9]
]
>> parse data-block [any block!]
== false
Simple!
PARSE is a good way to do that, since it returns TRUE if it can parse the entire block properly. PARSE happens also to be very fast.
Our data should be a block of blocks:
data-block: [
[1 2 3]
[4 5 6]
[7 8 9]
]
So you can simply check that each entry is a block:
>> parse data-block [any block!]
== true
Let's sabotage our data block:
data-block: [
[1 2 3]
none ; oops!
[4 5 6]
[7 8 9]
]
>> parse data-block [any block!]
== false
Simple!
|