Vera is a multiset rewriting system.
Vera is a multiset rewriting system designed to converse with computers, created by the same author as Modal. A program is made entirely of facts and rules:
|| The first character in a file assigns a spacer glyph. || A program is made of rules and facts. || Two spacers indicate the creation of facts || Facts are separated by commas, a matchbox, a log, paper | A rule has a left side | And a right side. | Facts on the left side | are replaced by facts in the right side | a flame, a log | a warm fire | a matchbox | a match, a match a box | a match, paper | a flame
Spacer
The first character in a file assigns a spacer glyph to be used to indicate rules and facts, the pipe character | is most commonly used:
| this is a rule | || this is a fact, this is another fact
Facts
A fact is the name for an item in the bag, the bag is the collection of all existing facts. A line starting with two spacing characters(also called an empty rule) will add facts to the bag, facts are comma separated:
|| a fact, another fact || one more fact, yet another, a last fact
Whitespace only exists to separate the words in a fact, but are not significant when matching facts. These 3 facts are equal:
|| a new fact, a new fact, a new fact
Rules
A rule is made of a left and often a right side, and indicate facts to remove and replace in the bag.
| a fact, another fact | the result | another rule | another result | a rule may not have a right side |
Evaluation
In turn, each rule is matched against the existing facts found in the bag, starting from the first rule, when a rule's left-hand side is found in the bag, these facts are replaced by the rule's right-hand side, and matching is started again from the top.
|flour, sugar, apples| apple cake |apples, oranges, cherries| fruit salad |fruit salad, apple cake| fruit cake || sugar, oranges, apples, apples, cherries, flour
Vera will match any amount found in the left-hand side, the following two rules are equivalent in Vera:
| an apple, hunger | a core | an apple, an apple, an apple, hunger | a core
Comments
Vera will discard a rule when all the facts found in its left-hand side are not present in any rule's right-hand side or declared as facts.
| yellow | This is a comment. | purple | This is not a comment. | # | This is also a comment. || purple
Implementation
The language runtime can be implemented in about 200 lines.
cc vera.c -o vera view raw
- Vera Interpreter(C89), used for this documentation.
- A Raven's Flyby, tutorial.
- Vera Wiki