Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Re: Function Prototypes

by chromatic (Archbishop)
on Jul 04, 2001 at 01:37 UTC ( [id://93697]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Function Prototypes
in thread Function Prototypes

Page 226 of Camel 3 says "...prototypes are taken into consideration only at compile time...". Dominus or Abigail will probably show up to correct me 30 seconds after I hit submit, but here goes at my explanation anyway. :)

Normally (without prototypes), subroutines are defined at compile time. During runtime, you'll get errors about undefined subroutines. There's too much left until runtime to verify things at compile time, what with importing and AUTOLOAD and method dispatch.

If you do something like the following -- with our without strict -- you'll get a message that indicates perl finds the construct ambiguous:

foo; sub foo { print "Fooing!\n" }
On the other hand, if you make it clear that foo is a subroutine and not a constant in void context, it's perfectly fine:
foo(); &foo; # or even my $foo = \&foo; $foo->(); sub foo { print "Fooing!\n" }
So it's not really a case of things having to be defined in the correct order because all of this happens at runtime. During compile time, Perl populates the symbol table and resolves what it can. That includes prototypes, and part of the reason seems to be so that you can use them almost as barewords just like built-in functions. That has to happen at compile time.

Dunno if that answers your question or muddies the matter. I have only seen a couple of good uses of prototypes, and rarely even think about them.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found