Steve Grazzini wrote:

> > What do you think is happening under the hood for something like
> >
> >   print for (0..0, 1, 2..5, func(6)..func(99))
>
> I think the whole list would have to be generated.  The optimization
> only applies to the case where there's just one range in place of the
> LIST.

I agree.  I'm not familiar with the ineternals of the language, but from a
logical perspective, a range is a function, equivalent logically to the basic
i++ C loop.  There is absolutely no reason to generate a list for something
that is so straigtforward in mathematical terms.  The line above processes a
logical list, where each discrete item has a very wide range of possiblities
for its value.

I find the Perl sytax a better match with the for or foreach in terms of
expressing the desired functionality.  The two posts we're discussing
demonstrate how well the Perl syntax promotes natural language programming.
The C-style syntax better demonstrates the difference between a list and a
range:

range;

for (int i = 0; i < 10; i++)

list:

for (ScalarArray  * item = ARGV, i = 0; i < item->count(); i++)

Okay, I'm a little rusty on my C, and I don't know the precise implementations
of range as opposed to list operations in Perl, but it seems pretty clear that
there is a lot more processing required for any list, especially in an untyped
language such as Perl, than for an integral range.  I assume that Perl has
some optimisations for lists that have only numeric values, but that is not
something I would rely on.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to