Question: 1 B ( 8 points ) : Define Closure for Function Calls with Zero or More Args. We will now redefine closures for functions with
B points: Define Closure for Function Calls with Zero or More Args.
We will now redefine closures for functions with zero or more args. When our function had one argument, our closures were defined as Closureid expr, env We would now like to define closures as Closureid idn expr, env where
id idn are the list of arguments for the function to be called.
expr is the body of the function and
env is the stored environment for static scoping.
beginaligned
text Value & Rightarrow text numDouble
& Rightarrow text closureString text Expr, Environment
& Rightarrow text error
endaligned
For Environment please use a scala immutable map from String to Value
sealed trait value
case class Numd: Double extends Value
case object Error extends Value
YOUR CODE HERE
case class Closureparams: ListString expr: Expr, env: MapString Value extends Value
defined trait Value
defined class Num
defined object Error
defined class Closure
BEGIN TEST
val v ClosureListxyz Plusx y Map.empty
val v ClosureNil Const Map.empty
val env: MapString value Mapx Numy v
val v ClosureListx Plusx Const env
passed
END TEST
cmdsc:: type mismatch;
found : ammonite.$sess.cmdwrapper.cmdIdent
required: string
val v ClosureListxyz Plusx y Map.empty
cmdsc:: type mismatch;
found : ammonite.$sess.cmdwrapper.cmdIdent
required: string
val v ClosureListxyz Plusx y Map.empty
cmdsc:: type mismatch;
found : ammonite.$sess.cmdwrapper.cmdIdent
required: string
val v ClosureListx Plusx Const env
cmdsc:: type mismatch;
found : cmdthis.cmd Const
required: string
val v ClosureListx Plusx Const env
Compilation Failed
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
