Fri, 12 Feb 2010 12:07:16 -0500, bearophile wrote: > /** > * Helper function: returns true if a class is marked with the "final" > attribute. */ > function isFinal(c) { > if (!c.attributes) > return false; > for each (let a in c.attributes) > if (a.name == 'user' && a.value == 'final') > return true; > return false; > } > function process_type(t) { > if (t.bases) > for each (let base in t.bases) > if (isFinal(base.type)) > error("class " + t.name + " extends final class " + > base.type.name, t.loc); > }
That kind of code is rather clumsy. Having written couple of toy languages, I really enjoy expressing the rules as immutable declarative axioms, e.g.: final_class_rule: node.metatype == class && node.hasBases ==> ! node.bases.exists(n => n.attributes.contains("final")) By using declarative notion, the ambiguity of rules can be tested and rules can be verified more easily.