When using parse
to extract values from data I often end up declaring globals to capture the copy
data.
For example,
numbers: none
rule: [ thru 5 copy numbers to 10 to end ]
parse [ 1 2 3 4 5 6 7 8 9 10 ] [ rule ]
What would be the best way to do this without using numbers
as a global?
Should I define a context
to wrapper the whole lot or is there a more elegant solution?
A context won't work without declaring the variables inside the context
>> unset 'a
>> context [ parse "aa" [ copy a to end ]]
>> a
== "aa"
In the same way you can use your parse rules inside a function with the variables declared as local to stop them polluting the global name space.