1. (10 pts) When the ea? function in Scheme is used for comparing symbols it mus
ID: 3600280 • Letter: 1
Question
1. (10 pts) When the ea? function in Scheme is used for comparing symbols it must return # t if and only if the the two symbols have the same name (where uppercase and lowercase characters are not distin- guished). E.g. (eg? (eg? (eg? ,x , x) returns#t ,x , X) returns#t ,x ,y) returns#f With our current implementation, the parser constructs a new Ident object for every occurrence of a symbol. For comparing symbols, it is, therefore, necessary to use string comparison for comparing the names stored in these Ident objects. Explain, how you would modify your processing of symbols (data structure, lexical analysis, and parsing), so that eq? could be implemented using simple pointer comparison, i.e., using-in C#, C++, or Java. 2. (10 pts) Suppose, we need to debug somebody else's program. We suspect that there is a problem with the method wizbang ) in class Widget or with how that method is called. We cannot modify class Widget, nor can we modify the client code that contains the calls to Widget.wizbang (), since we don't have those sources. However, we can modify the code where Widget objects are created and we can create new classes In order to better understand what this method does, we would like to print the values of the parameters and the return value into a log file every time Widget.wizbang) is called. Explain, how you would produce this log file given the constraints that neither class Widget nor the client can be modified.Explanation / Answer
# define a function
def lcm(x, y):
"""This function takes two
integers and returns the L.C.M."""
# choose the greater number
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
# change the values of num1 and num2 for a different result
num1 = 54
num2 = 24
# uncomment the following lines to take input from the user
#num1 = int(input("Enter first number: "))
#num2 = int(input("Enter second number: "))
print("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.