> The normal problem with this type of structure is that
> the previous
> statement would create 2 array copies, and 3 loops for
> most compilers. In
> perl speak, it might look like:
> $dummy1[$_] = $b[$_]*$c[$_] for (0..$#b-1);
> $dummy2[$_] = $d[$_]+$dummy1[$_] for (0..$#dummy1-1);
> $sum+=$_ for (@dummy2);
> (Sorry if this isn't very idiomatic perl--it's not really
> my native
> language.)
> 
> Progressive C++ numeric programming libraries like POOMA
> and Blitz++ use
> template meta-programming techniques to implement
> 'expression templates'.
> Templates are used to create the parse tree for these
> kind of array
> expressions at compile time, and the compiler then
> optimises out the extra
> loops and array copies to create something like:
> $sum+=$b[$_]*$c[$_]+$d[$_] for (0..$#b-1);
> 
> Without this optimisation, array semantics become next to
> useless for
> numeric programming, because their overhead is just so
> high. But writing
> numericly intensive programs without array semantics is
> messy--they become
> littered with control structures and loops (which is
> particularly
> unintuitive for mathmaticians used to the compact
> notation of mathematics).
> 
> So, could perl 6 do this optimisation (assuming that the
> array
> notation/folding stuff makes its way into the language)?
> Given that some
> amount of compilation or interpretation will presumably
> still be done at
> run-time, perhaps this is much easier in perl than in
> C++...

This actually leads to a much more general question, namely
passing of arrays to functions. For ppcode at least and
probably any code using the perl API, it should be possible
and IMHO desirable to push the AV* (or equivalent), rather
than expanding the array and pushing each of its elements.
Furthermore, if we do this, it would make passing named
array arguments (sub foo (@baz, @qux) { ... }) much
simpler. 
If a subroutine asks for @_, than we can go the old way and
push everything, but reducing the number of stack pushes on
list operators could be a major win.

-- BKS

__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/

Reply via email to