Hacker News new | ask | show | jobs
by Fixnum 4661 days ago
For one thing, you generate as few as possible by aggressively fusing away intermediate lists (at least if your language is pure).

Also, the garbage collector will often move lists into contiguous region(s) of memory.

More to the point, though, sometimes a list is the appropriate data structure for a problem (like returning all intermediate results from the Collatz call, where you don't know how many there will be). Sure, you could use an array and double its size every now and then, but you're doing an awful lot of violence to your program just to handle something the runtime could take care of for you :)

And yes, I know there will be a slight performance penalty under many circumstances.