// this is an example of the higher-order rule apply // trans matches a list in which the first element is the name of a rule, and // the remaining elements are matched by that rule. (think of it as a dispatcher) // :x is shorthand for anything:x, and [...] is the syntax for matching a list object ometa Translator { trans = [:x apply(x):r] -> r } ometa CodeGen <: Translator { lit = anything, plus = trans:x trans:y -> ("(" + x + "+" + y + ")"), times = trans:x trans:y -> ("(" + x + "*" + y + ")") } translation = CodeGen.match([`times, [`lit, "6"], [`plus, [`lit, "3"], [`lit, "4"]]], "trans") eval(translation)