Question: Code based on this. The blue box is a step by step explanation on how to implement the code. It also has two attributes: Py_func:

Code based on this. The blue box is a step by step explanation on how to implement the code. It also has two attributes: Py_func: the python function that implements the built-in scheme procedure. Need_env: a Boolean flag that indicates whether or not this built in procedure will need the current enviornment to be passed in as the last argument.The environment is required


attachment1.png


 

BA scheme apply takes the procedure object, a list of argument values, and the current environment. args is a Scheme list represented as a Pair object or nil. scheme_eval_apply.py 1 scheme_builtins.py 4 scheme_eval_apply.py > scheme_apply scheme pair.py 40 41 scheme apply (procedure, args, env): 42 Your implementation should do the following: 43 44 45 if not isinstance (env, Frame): Convert the Scheme list to a Python list of arguments. Hint: args is a Pair, which has a .first and .rest attribute. 46 47 if is instance (procedure, Builtin Procedure): 48 49 If procedure.need_env is True, then add the current environment env as the last argument to this Python list. Return the result of calling procedure.py_func on all of those arguments. Use *args notation: f(1, 2, 3) is equivalent to f(*[1, 2, 3]). Do this part within the try statement provided, after the line that says try: . We have already implemented the following behavior for you: If calling the function results in a TypeError exception being raised, then the wrong number of arguments were passed. The try statement handles this 50 51 52 53 "Apply Scheme PROCEDURE to argument values ARGS (a Scheme list) in Frame ENV, the current environment.""" validate_procedure (procedure) assert False, "Not a Frame: {}".format(env) # BEGIN PROBLEM 2 # convert args (which is a Pair) into a Python list # iterate through args using args.first and args.rest, # and put each of the items in a Python list # check if procedure.need_env is True, make sure to add env to end of Python list # END PROBLEM 2 A 54 try: 55 56 57 58 59 60 61 62 63 64 65 66 # BEGIN PROBLEM 2 # call procedure.py_func on Python list of args # make sure to use *args notation # return result # END PROBLEM 2 except TypeError as err: raise SchemeError('incorrect number of arguments: {0}'.format(procedure)) elif isinstance (procedure, Lambda Procedure): # BEGIN PROBLEM 9 "kokk YOUR CODE HERE ****" # END PROBLEM 9 elif isinstance (procedure, MuProcedure): 67 # BEGIN PROBLEM 11 1A4 Live Share Ln 57, Col 28 Spaces: 4 UTF-8 3.10.0 64-bit LF Python Prettier

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 Algorithms Questions!