git @ Cat's Eye Technologies Treacle / a585cd2
Markdown tweaks and minor spelling/wording tweaks. catseye 10 years ago
1 changed file(s) with 12 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
77 ------------
88
99 Treacle is a programming language based on an extended form of
10 term-rewriting which we shall call, somewhat innacurately (or at least
11 arbitrarily,) *context rewriting*.
12
13 Like Arboretuum, its successor built around *forest-rewriting*, Treacle
10 term-rewriting which we shall call, somewhat inaccurately (or at least
11 arbitrarily,) _context rewriting_.
12
13 Like Arboretuum, its successor built around _forest-rewriting_, Treacle
1414 was intended as a language for specifying compilers. Treacle is somewhat
1515 more successful at pulling it off, however; context rewriting
1616 encompasses, and is more expressive than, forest-rewriting.
1717
1818 Context rewriting is meant to refer to the fact that Treacle's rewriting
19 patterns may contain holes – designated "containers" for subpatterns
19 patterns may contain _holes_ – designated "containers" for subpatterns
2020 which may match not just the *immediate* child of the term which the
2121 parent pattern matched (as in conventional term-rewriting) but also *any
2222 one of that child's descendents*, no matter how deeply nested.
3030 pattern.
3131
3232 Context rewriting also deconstructs the conventional concept of the
33 variable, splitting it into a name and a wildcard. Any pattern or
33 variable, splitting it into a _name_ and a _wildcard_. Any pattern or
3434 subpattern may be named, not just wildcards. Even holes may be named. At
3535 the same time, wildcards, which match arbitrary terms, may occur
3636 unnamed. Upon a successful match, only those terms which matched named
3737 patterns are recorded in the unifier.
3838
39 Further, each rule in Treacle may contain multiple terms (replacements)
39 Further, each rule in Treacle may contain multiple terms (_replacements_)
4040 on the right-hand side of a rewriting rule, and each of these may have
41 its own name. When the term undergoing rewriting (called the subject) is
41 its own name. When the term undergoing rewriting (called the _subject_) is
4242 rewritten, each named replacement is substituted into the subject at the
4343 position matched by the part of the pattern that is labelled by that
4444 same name.
4545
46 Lastly, replacements may contain special atomic terms called newrefs.
46 Lastly, replacements may contain special atomic terms called _newrefs_.
4747 When a newref is written into the subject, it takes the form of a new,
4848 unique symbol, guaranteed (or at least reasonably assumed) to be
4949 different from all other symbols that are in, or could be in, the
8282
8383 Now we are ready to give some examples.
8484
85 ### Patterns
85 ### Patterns ###
8686
8787 - The pattern `(a b (? X *))` matches `(a b (c (d b)))`, with the
8888 unifier `X=(c (d b))`. Also, `(a (? Y *) (c (d (? Y *))))` matches
110110 search the contents of the 3rd subterm, for whatever the 2nd subterm
111111 is.
112112
113 ### Rules
113 ### Rules ###
114114
115115 - Say we have a rule where the pattern is `(a b (:i (? X (d b))))`,
116116 and the lone replacement is `X : a`. This rule would match the
193193 of information in the tree of terms that relate to the reduction you
194194 want to accomplish, they have to be in a bounded distance from, and in a
195195 fixed relationship with, each other. If some piece is far away, it will
196 have to be brought – *literally* brought! – to bear on the situation, by
196 have to be brought to bear on the situation – *literally* brought, by
197197 moving it through the tree through successive "bubbling" rewrites.
198198
199199 Forest-rewriting eases this by having multiple independent trees: some