|
||||||
|
The REBOL programming language contains an important concept. That of Dialects. With a dialect the programmer can start to write business rules.
The most exciting thing about REBOL is its dialects. This does not mean that the programming language changes according the part of the world in which it is used. Instead it means that the programmer can produce a project or problem specific set of grammar rules that can handle blocks of data. REBOL (see A Brief Introduction to REBOL Programming) can then parse the data through the grammar rules. This makes REBOL the perfect language for creating business rules. Creating a Very Simple REBOL DialectA REBOL dialect consists of:
Fortunately the programmer can carry out each of these steps very quickly. That is, of course, assuming that they have a good understanding of the rules to be modelled. Creating a REBOL Block of DataA REBOL block of data is simple a statement defining the data to be used. For example, consider the block: daughters: [
[name "Mary-Jane" age 18 got-home 22:30:00]
[name "Joleene" age 21 got-home 24:30:00]
]
Here the business rule is simple: whoever gets home on time is allowed out again; whoever gets home late is grounded. The next step is, therefore, to create the grammar rules. Creating REBOL Grammar RulesFirst any required variables need to be set: home-time-rule: [
some [
['name [set who string!]]
|['got-home [set actual time!]]
|['age opt [set age integer!]]
]
There are a few points to take note of in this code:
Next the business rule for the grammar block can be created: (either actual <= 22:30:00
[(print [who "is allowed out again"])]
[(print [who "is grounded"])]
)
]
REBOL does not have an if..then..else statement. Instead it uses either in the form: (either
[true statement]
[false statement]
)
Now the dialect is ready for use. REBOL ParsingThe REBOL dialect is accessed by using the parse key word. The technique consists of stepping through the data block and applying the grammar rules to each sub-block: foreach daughter daughters [parse daughter home-time-rule]
And the end result is: Mary-Jane is allowed out again
Joleene is grounded
Of course, this a very simple business rule (after all Joleene will probably complain about having to come in at the same time as her younger sister) however it does show how easy it is to create a REBOL dialect. In a very short time a programmer can build extensive and complicated business rules which can be applied to any relevant data.
The copyright of the article How to Create a REBOL Dialect in Computer Programming Languages is owned by Mark Alexander Bain. Permission to republish How to Create a REBOL Dialect in print or online must be granted by the author in writing.
Comments
Jul 9, 2009 2:40 PM
Guest :
1 Comment:
|
||||||
|
|
||||||
|
|
||||||