Parcourir la source

python: pattern matching

Peter Thiemann il y a 3 ans
Parent
commit
a29d12c2f1
1 fichiers modifiés avec 1 ajouts et 3 suppressions
  1. 1 3
      book.tex

+ 1 - 3
book.tex

@@ -16710,9 +16710,7 @@ class InterpLdyn(InterpLlambda):
 
   def untag(self, v, expected_tag, ast):
       match v:
-        case Tagged(val, tag):
-          if tag != expected_tag:
-            raise Exception('expected tag ' + expected_tag + ', not ' + ' ' + repr(v))
+        case Tagged(val, tag) if tag == expected_tag:
           return val
         case _:
           raise Exception('expected Tagged value with ' + expected_tag + ', not ' + ' ' + repr(v))