In both Python and Haskell, list comprehension is a single function combining what Snap! calls KEEP and MAP. Something like:
or, in Snappified Python style:
If I understand correctly, it’s a concise syntax that’s also faster at run time because of a single pass.
Snap! however has a very different List comprehension (library) block:
I don’t get it. What is its purpose? Why is it also called List comprehension? Does anyone have an example of its use?
The purpose is to hyperize an arbitrary two-input reporter, in this case NUMBERS FROM. The first list provides FROM inputs, and the second provides the corresponding TO inputs.
I never understood what those other people mean by "list comprehension," so I'm the wrong person to ask why this counts.
Oh, LEAF-RANK is for situations in which you have, say, a list of points, where each point is an x,y list, so you'd use LEAF-RANK 1 instead of 0 to make a point be the unit datum. If you had a line segment, represented as a list of two endpoints, you'd use LEAF-RANK 2 to treat the whole thing as one datum.
I'm sure Jens can provide a more useful example.
I have understood that the word "comprehension" in Python “list comprehension” is not to be interpreted in the ordinary sense of "understanding", but rather as a kind of neologism, derived from "comprehensive": a jack-of-all-trades.
That would be great. And perhaps other users? (I’m surprised apparently no other topics on this forum have been raised regarding Snap! ‘s list comprehension, or leaf-rank as I think it was formerly called, wasn’t it? For all I know it may be a truly useful feature that’s hardly used however because only a few people know what it can achieve).