Commits

Waldemar Kornewald  committed 2bd23af

fixed apply() rule and added unit test for it

  • Participants
  • Parent commits 8bf615d

Comments (0)

Files changed (2)

 
         else:
             raise NameError("No rule named '%s'" %(ruleName,))
-
-    def rule_apply(self, ruleName, *args):
-        return self.apply(ruleName, *args)[0]
+    rule_apply = apply
 
     def _apply(self, rule, ruleName, args):
         """

File test/test_pymeta.py

         self.assertEqual(g.fact([3]), 6)
 
 
+    def test_apply_rule(self):
+        """
+        Productions can pattern-match on arguments even if they're lists.
+        """
+        g = self.compile("""
+              fact 0                    -> 1
+              fact :n = fact((n - 1)):m -> n * m
+              domany = interp*
+              interp = [:name apply(name):x] -> x
+           """)
+        self.assertEqual(g.interp([['domany', ['fact', 3], ['fact', 5]]]),
+                         [6, 120])
+
+
     def test_listpattern(self):
         """
         Brackets can be used to match contents of lists.