defined trait Expr
Tuesday, September 24, 2024
What questions does your neighbor have?
What’s variable binding?
What’s variable scope?
How do you bind a variable in Scala?
In JavaScript?
Let’s extend our abstract syntax type Expr
.
defined trait Expr
Let’s define a function to compute the free variables of a JavaScripty expression:
defined function freeVars
e_n: N = N(n = 2.0) e_plusnn: Plus = Plus(e1 = N(n = 2.0), e2 = N(n = 2.0)) e_var: Var = Var(x = "four") e_plusvarvar: Plus = Plus(e1 = Var(x = "four"), e2 = Var(x = "four")) e_constdecl: ConstDecl = ConstDecl( x = "four", e1 = Plus(e1 = N(n = 2.0), e2 = N(n = 2.0)), e2 = Plus(e1 = Var(x = "four"), e2 = Var(x = "four")) )
What is the meaning of an expression with free variables?
:
Compilation Failed
Let’s implement rename
that renames all variables into "x0"
, "x1"
, etc.
defined function rename