Re: Lazy evaluation?



Mirco Wahab wrote:
Michele Dondi wrote:
On Tue, 13 Feb 2007 20:14:13 -0600, Rob Hoelz <hoelz@xxxxxxxx> wrote:
local $\ = "\n";
foreach $num (1..1000_000_000) {
print $num;
}

I seem to remember that this particular one is optimized, but I'm not
really sure if up to the point of lazy evaluation.

The above (foreach list) *is* lazy evaluated (at least
in my in 5.8.8/Linux), whereas the list in

That is not lazy evaluation. Perl is just internally evaluating:

foreach $num (1..1000_000_000) {
print $num;
}

As:

for ( $num = 1; $num <= 1000_000_000; ++$num ) {
print $num;
}


Lazy evaluation would imply that the assignment to $num is delayed until it is
actually required for the print() function which is not what perl does.



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.



Relevant Pages

  • Re: Lazy evaluation?
    ... foreach $num { ... does Perl use lazy evaluation? ...
    (comp.lang.perl.misc)
  • Re: Bidirectional mapping
    ... SAT SUN]? ... For quick and dirty and highly readable I usually do it like: ... foreach { ... set day_num($day) $num ...
    (comp.lang.tcl)
  • Lazy evaluation?
    ... foreach $num { ... does Perl use lazy evaluation? ...
    (comp.lang.perl.misc)
  • Re: Lazy evaluation?
    ... Michele Dondi wrote: ... foreach $num { ... really sure if up to the point of lazy evaluation. ...
    (comp.lang.perl.misc)
  • Ways of ensuring integers in the database are seen as numbers in perl?
    ... I'd like my database returned integers to look like integers to Perl but they currently don't until I add 0 to them. ... The reason for this is that adding 0 to a Perl scalar seems to persuade Perl the scalar is an integer. ... $num as returned from database: ...
    (perl.dbi.users)