4 ms·
Why would map have conditions? //pseudocode map(f, ns) for i in (0 .. ns.length - 1) f(ns[i])
by islon 6y ago
Why would map have conditions?
//pseudocode
map(f, ns)
for i in (0 .. ns.length - 1)
f(ns[i])
- Sharlin 6y agoWell, the loop in your `map()` does obviously have a halting condition. But I believe by map, the GP meant the associative array used by the implementations to lookup the correct output.
- nonameiguess 6y agoIn most languages, looping is implemented with conditional jumps, but I actually think Python is unique in this case because of the way it uses exceptions for flow control. Rather than checking an index to see if the loop has reached the end of an iterator, the iterator just raises a StopIteration exception and the runtime catches it. The key lookup in dict definitely has conditionals, though. Of course, the guy could get rid of that by just using an 11-element array and addressing directly instead of hashing integers as keys.
- layoutIfNeeded 6y ago>Rather than checking an index to see if the loop has reached the end of an iterator, the iterator just raises a StopIteration exception and the runtime catches it. And how does the iterator know that it should raise an exception? A conditional.
- draganm 6y agobecause for has a termination condition ...
- Jtsummers 6y agoThe map data structure, not the map higher order function. As implemented, most map data structures will have a conditional in their lookup functions to handle the case of collisions or a key being absent from the map.