develooper Front page | perl.perl6.language | Postings from May 2004

signature of a program

Thread Previous
Dave Whipp
May 12, 2004 12:50
signature of a program
Message ID:
"Luke Palmer" <> wrote
> Well, the IO-objects are iterators, and you use <$iter> to iterate.  It
> makes sense that <> would iterate over $*ARGV by default.

When I read this, I instinctively thought to myself: "why does this need to
be global?". And that thought progressed to: "what is the signature of a
main program?"

When you start a perl program, you don't need a "main" function, but the
program is a lexical scope from which you return. its just the "sub"
declaration that is implicit:

  sub main::_(*@ARGV) returns int {...}

or some such thing. Is this really the best signature we could use? Given
that we want a ref to the array to be the default topic, perhaps the
signature is:

  class main is program {
    has @.ARGV is rw;
    has %.ENV is rw;
    method _() returns int { ... }

We could then paste any number of program attributes into that class: %.ENV,
$.STDIN, $.STDOUT, etc. Thing like $*IN would just be aliases to those
attributes: @*ARGV := .ARGV; etc.

If I stretch my imagination a little, I could even see user-code creating
other instances of program you use in place of functions like system and

  sub qw(Str $exe) { $exe ) as string }

OK, maybe that's not quite what you'd want, but I you get the picture (I


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About