in reply to map: chaining vs. nesting
When I see those constructs, I wonder whether Perl is doing anything clever to avoid unnecessary copying
No, a list is generated at the end of each map. So the ST, for example:
my @sorted_data = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map {[ do_something($_), $_ ]} @unsorted_data;
Takes about 3 times as much memory as @unsorted_data orginally used. It also happens to be efficient because of an optimized sort step. CPU/memory tradeoffs generally favor the CPU--in fact, Perl itself is one gigantic CPU/memory tradeoff.
Further meditiation: LISP and other old interpreted languages were not well received when they were still young. Its detractors claimed it took too much computing power to handle the virtual machine it required. Today, a lot of very popular languages run under VMs (Perl, Java, Python, C#/.NET, etc.), and often run without significantly cutting into the resources available on a modern system. So the old reasoning should be considered moot.
However, there is a second reason why LISP and other functional langauges are inefficient--that being the memory requirements to handle the massively-chained operations that functional programming styles encourage. With significant ammounts of data, it could easily overwhelm the RAM of even modern systems.
----
send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: map: chaining vs. nesting
by diotalevi (Canon) on Jun 18, 2004 at 14:35 UTC | |
|
Re^2: map: chaining vs. nesting
by danderson (Beadle) on Jun 18, 2004 at 18:42 UTC | |
by Errto (Vicar) on Jun 19, 2004 at 01:17 UTC | |
by FoxtrotUniform (Prior) on Jun 18, 2004 at 18:54 UTC |