소스 검색

more pythonic

Peter Thiemann 3 년 전
부모
커밋
a7e15936d4
1개의 변경된 파일2개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 6
      book.tex

+ 2 - 6
book.tex

@@ -13246,9 +13246,7 @@ class InterpLfun(InterpLtup):
   def apply_fun(self, fun, args, e):
       match fun:
         case Function(name, xs, body, env):
-          new_env = {x: v for (x,v) in env.items()}
-          for (x,arg) in zip(xs, args):
-              new_env[x] = arg
+          new_env = env.copy().update(zip(xs, args))
           return self.interp_stmts(body, new_env)
         case _:
           raise Exception('apply_fun: unexpected: ' + repr(fun))
@@ -13395,9 +13393,7 @@ class TypeCheckLfun(TypeCheckLtup):
       return
     match ss[0]:
       case FunctionDef(name, params, body, dl, returns, comment):
-        new_env = {x: t for (x,t) in env.items()}
-        for (x,t) in params:
-            new_env[x] = t
+        new_env = env.copy().update(params)
         rt = self.type_check_stmts(body, new_env)
         check_type_equal(returns, rt, ss[0])
         return self.type_check_stmts(ss[1:], env)