Diagnostic Quiz
Problems
6. How many times will an lambda be evulated in an Infinite List
If you call
get(n), the the lambda expression in theitearte()will be ecaluatedntimes!

Since get(n), and n is 5, the lambda expression will be evaluated 5 times!
8-11. Use Heap Diagram to trace the program
When you call
infiList1 = InfiniteList.operation, theheadandtailfields in theinfiList1point to two anonymous classes implemented in lambdas which capture the variable appeared in that lambda.When you call
infiList2 = infiList1.opeartion, theheadandtailfields in tehinfiList2point to two anonymouse classes also, but with anotherthisfield in each of them, which points toinfiList1.Also include the code, the implementation for some
InfiniteListoperations and pictures from the lecture into the Cheatsheet!
Given this modified version of InfiniteList::map,
What will be printed by the code snippet below?
This question is a bit tedious, but the stack and heap diagram should be easy to draw following the above rules. The answer is 7 7 20 20 8 8 21 21.
13. Infinite Loop in Stream
sorted()anddistinct()should only be called on finite streams. Otherwise, the program will enter an infinite loop.
Tips
When calling
get(n)in EagerList or InfiniteList, notice the the index of the element in the list starts from 0!Stack and Heap Diagram for Infinite List Rules of thumb
When you call
infiList1 = InfiniteList.operation, theheadandtailfields in theinfiList1point to two anonymous classes implemented in lambdas which capture the variable appeared in that lambda.When you call
infiList2 = infiList1.opeartion, theheadandtailfields in tehinfiList2point to two anonymouse classes also, but with anotherthisfield in each of them, which points toinfiList1.Also include the code, the implementation for some
InfiniteListoperations and pictures from the lecture into the Cheatsheet!
sorted()anddistinct()should only be called on finite streams. Otherwise, the program will enter an infinite loop.
Last updated