5 Fun with Functions
This assignment is designed to give you practice with variable bindings.
Submit a single Shplait file (with extension rhm).
5.1 Time Estimate
This assignment should take you 30 minutes to 3 hours.
If you are struggling to complete this assignment in this amount of time, please seek TA or instructor help.
5.2 Deliverables
Start from your interpreter with environments and let bindings.
Submit a single Shplait file (with extension rhm), that supports the following additional language features.
Let* bindings, which bind multiple variables in order, with previous bindings in scope for later ones
Default parameters, with the expression evaluated in the closure’s environment
Named parameters, where the identifier of the parameter is expected to be equal to the closure’s bound variable identifier
|
| ||||
| ||||
|
If a parameter is not provided and there is no default expression, an "invalid number of arguments" error should be thrown.
For example, interp(parse('f()'), mt_env, [parse_fundef('fun f(x = 0): x + 1')]), should evaluate to 1.
|
For example, interp(parse('f(x = 1)'), mt_env, [parse_fundef('fun f(x): x + 1')]) should evaluate to 2, but the interp(parse('f(y = 1)'), mt_env, [parse_fundef('fun f(x): x + 1')]) should throw an error containing "invalid named argument".
Your final interpreter should support all three of these operations. Ensure you have adequate tests to cover both successful and error cases.