Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to Why is const x const not a const?

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://949268]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found