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

signature of a program

Thread Previous
From:
Dave Whipp
Date:
May 12, 2004 12:50
Subject:
signature of a program
Message ID:
20040512195038.3506.qmail@onion.perl.org
"Luke Palmer" <luke@luqui.org> 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
exec.

  sub qw(Str $exe) { program.new( $exe ) as string }

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


Dave.



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About