Question: Please use Racket also test it Part 2 Functions that Accept Multiple Arguments Extend the interpreter to support multiple or zero arguments to a function,

Please use Racket also test it

Part 2 Functions that Accept Multiple Arguments Extend the interpreter to support multiple or zero arguments to a function, and multiple or zero arguments in a function call. For example, {define {area w h} {* w h}} defines a function that takes two arguments, while {define {five} 5} defines a function that takes zero arguments. Similarly, {area 3 4} calls the function area with two arguments, while

{five} calls the function five with zero arguments. At run-time, a new error is now possible: function application with the wrong number of arguments. Your interp function should detect the mismatch and report an error that includes the words wrong arity. To support functions with multiple arguments, youll have to change fd and appE and all tests that use them. When you update the parse function, note that s-exp-match? supports ... in a pattern to indicate zero or more repetitions of the preceding pattern. Beware of putting the multi-argument application pattern too early in parse, since that pattern is likely to match other forms. In addition, youll need to update the parse-fundef function that takes one quoted define form and produces a Func-Defn value. Just to clarify: Supporting multiple-argument functions does not mean changing operations like + or *. Although + and * are functions in Plait, theyre treated as non-function operator forms in Curly. Some examples: (test (interp (parse `{f 1 2}) (list (parse-fundef `{define {f x y} {+ x y}}))) 3) (test (interp (parse `{+ {f} {f}}) (list (parse-fundef `{define {f} 5}))) 10) (test/exn (interp (parse `{f 1}) (list (parse-fundef `{define {f x y} {+ x y}}))) "wrong arity") Remember that Plait provides map, which takes a function and a list, and applies the function to each element in the list, returning a list of results. For example, if sexps is a list of S-expressions to parse, (map parse sexps) produces a list of ExprCs by parsing each S- expression. But also remember that map doesnt work for everything. Sometimes, when you have a list to process (or maybe two lists in parallel), then you need to write a new function using the template for lists.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!