These are the instructions that will also be on the real final, but of course this is just a practice final:You have 90 minutes to complete the exam. Only your first submission will count toward your grade. You may use any course materials (videos, slides, reading notes, etc. ). You may use the ML, Racket, and Ruby REPLs. You may use text editors. You may use the standard-library documentation for the languages. You may not use the discussion forum. You may not use other websites related to programming. (Sites like dictionaries for translating English words are okay to use. )
Removing parentheses from around a function call can change a program's meaning, but it is always okay to add an extra set of parentheses.
The library function set-mcar! can be implemented in terms of set!.
An anonymous function can be written anywhere an expression is allowed.
Racket is a weakly typed language.
Thunking is a programming idiom that does not need special support in the language beyond first-class function closures.
At the top-level in a file, an earlier function definition can refer to a later function definition.
(define (twice-each s) (lambda () (let ([pr (s)]) (cons (car pr) (lambda () (cons (car pr) (twice-each (cdr pr))))))))
(define (twice-each s) (let ([pr (s)]) (cons (car pr) (lambda () (cons (car pr) (twice-each (cdr pr)))))))
(define (twice-each s) (lambda () (let ([pr (s)]) (cons (car pr) (cons (car pr) (twice-each (cdr pr)))))))
(define (twice-each s) (let ([pr (s)]) (cons (car pr) (lambda () (cons (cdr pr) (twice-each ((cdr pr))))))))
Rate this question:
Evaluating (my-force (my-delay (lambda () e))) always produces the same result as evaluating e.
Evaluating (my-delay (my-force (lambda () e))) always produces the same result as evaluating e.
Evaluating (my-force (my-delay (my-delay (lambda () e)))) always produces the same result as evaluating e.
Evaluating (my-force (my-delay (my-delay (lambda () e)))) will not evaluate e.
Rate this question:
Calling version A is equivalent to calling version B.
Calling version A evaluates e more times than calling version B.
Calling version A does not terminate but calling version B does terminate.
Version A and version B both always return 42.
Rate this question:
(mlet "x" (int 0) (mlet "x" (int 1) (mlet "f" (fun #f "y" (var "x")) (call (var "f") (var "x")))))
(mlet "f" (mlet "x" (int 0) (fun #f "y" (var "x"))) (mlet "x" (int 1) (call (var "f") (var "x"))))
(mlet "x" (int 0) (mlet "f" (fun #f "y" (mlet "x" (int 1) (var "x"))) (call (var "f") (var "x"))))
(mlet "x" (int 0) (call (fun #f "y" (var "x")) (var "x")))
Rate this question:
The type system before this change is sound and complete and after this change is sound and complete.
The type system before this change is sound and not complete and after this change is sound and not complete.
The type system before this change is sound and complete and after this change is sound and not complete.
The type system before this change is sound and complete and after this change is not sound but is complete.
The type system before this change is sound and not complete and after this change is not sound and not complete.
If you are writing a function/method that should be called only with values of one type, it is more convenient because you do not need to add a run-time type test to the function/method body.
Static checking catches all the simple bugs, so your testing only has to test how multiple functions/methods are used together.
If you change the return type of a function/method, the type-checker will give a list of callers that still assume the old return type.
Languages with static type systems cannot have security bugs where "anything might happen."
A language with static typing always supports generic types, which are more powerful than subtyping.
Rate this question:
B.new.m1
B.new.m3
C.new.m1
C.new.m3
D.new.m1
D.new.m3
Rate this question:
It should be a run-time error in Ruby to send the push message to an array holding 0 elements.
In Ruby, a method can use yield to call the block provided by the caller even if the method did not indicate that it expected a block.
In Ruby, the class of object nil is nil, so no methods are defined on this object.
In OOP, defining a method in a class that just returns the value of a field (what Ruby calls an instance variable) is not useful: it is analogous to unnecessary function wrapping.
Ruby has a notion of subclassing but no notion of subtyping.
Dynamic dispatch means that a call like self.foo in a method defined in class A could call code in a subclass of A that the writer of the class A code does not know exists.
If class C overrides method m from a superclass, then in the body of C's definition of m, the keyword super is just syntactic sugar for m.
Rate this question:
Provide a reusable Button class for a graphical interface that subclasses can specialize by changing the size, color, and text of the button.
Provide a class like ML's lists that has a sort method that reuses methods provided by standard-library mixins.
Provide classes that represent each of the "essential" amino acids, each with a method resultOfCombining that takes an argument that is another "essential" amino acid and returns the protein resulting from combining the two amino acids.
Provide a mixin that is like Enumerable except it raises an error if any of its methods are used on an empty collection, where the notion of emptiness is provided by classes via an empty? method.
Rate this question:
F1 r1
F1 r2
F1 r3
F1 r4
F2 r1
F2 r2
F2 r3
F2 r4
F4(f1,42)
F4(f2,42)
F4(f3,42)
Quiz Review Timeline +
Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.
Wait!
Here's an interesting quiz for you.