|
|
|
|
|
by wyager
4384 days ago
|
|
>lazy evaluation is one of those features where i have absolutely no idea what benefit it actually provides Good question. Let's say you have a program like this little python example: inputs = [raw_read() for i in range(1000)] # Read numbers from command line
numbers = map(int, inputs) # Turn them into integers
for num in numbers: # Check for 42
if num == 42:
return true
return false # It's not there
If you use lazy evaluation, each item in the "map" object will only be calculated as needed. So if the first item in the "inputs" list is "42", it will only do a single string-to-integer conversion.If you use greedy evaluation, it will map all strings to integers at once, which might be wasteful. There are other benefits as well; this is the most obvious. |
|