laziness, impatience, and hubris | |
PerlMonks |
Re: Why is const x const not a const?by The Perlman (Scribe) |
on Jan 22, 2012 at 18:36 UTC ( [id://949268]=note: print w/replies, xml ) | Need Help?? |
I think for the same reason why the alias $_ is a read-only value here
for (1,2,3) { } but not here for (1 .. 3) { } In the first case Perl (historically) tries to avoid the overhead to allocate a variable by pointing to the already existing literal in source code. At least thats what's happening in (e)Lisp, one of the languages which influenced Larry. Literals can only be constant since the source shouldn't be changed. The operators x and .. OTOH calculate the values, there are no source positions which can be used for optimization. I don't know if this optimization still makes sense, but I think it's at least the historical motivation.
---The Perlman
In Section
Seekers of Perl Wisdom
|
|