[Tutor] function declaration problems perhaps?

Alan Gauld alan.gauld at btinternet.com
Wed Jul 25 16:49:29 CEST 2007


"nibudh" <nibudh at gmail.com> wrote

> in perl this works:
>
> #!/usr/bin/env perl
> hello("World");
>
> sub hello {
>    print "Hello ". $_[0] . "\n";
> }


Perl executes differently to Python in that it does a compilation 
stage
before executing. Therefore Perl knows about all the function 
definitions
prior to executing any code. Python compiles modules which it imports
but not scripts which it executes.

> I have a vague recollection that ASP works in a similar way to 
> python hence
> the "hunch" i had earlier but i could be wrong. It's been a while 
> since i've
> done programming.

Most interpreted languages work this way.
Even the original versions of C worked that way although I thiunk more
recent (ANSI/ISO compliant?) versions no longer need the strict 
ordering,
and Pascal also does it that way even though they are pure compiled
languages. In the case of Pascal it is because Pascal is designed to
be a single pass comilation language - which is why Borland's Object
Pascal comiles so quickly in Delphi!

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list