Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Perl and common subexpressions

by dws (Chancellor)
on Dec 23, 2004 at 07:16 UTC ( [id://417015]=note: print w/replies, xml ) Need Help??


in reply to Perl and common subexpressions

Unfortunately, unlike C, Perl has to contend with something a little crazier: Tied hashes and arrays.

And function calls. In

t = x->y->z->a->b[5];
any of y, z, or a can be methods, with or without side-effects, and with no guarantee that they'll return the same thing on subsequent calls. In the face of such flexibility, static analysis optimizations are non-starters.

Replies are listed 'Best First'.
Re^2: Perl and common subexpressions
by theorbtwo (Prior) on Dec 23, 2004 at 15:08 UTC

    It's trivial to tell the difference between a method call and a hash lookup for the perl compile -- you're just having issues with C vs perl syntax. (Getting e, an element of the struct pointed to by p in C is p->e, which looks a lot like calling a method, m, on an object $o in Perl -- $o->m)

    On the other hand, when it /is/ a method call, perl can't tell /what/ method is being called, because it doesn't know the type of the object you're calling the method on until runtime. The m method on Foo::Bar might be side-effect free, while the m method on Baz has side-effects.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found