Here's a hackish way to implement #1:

#!perl6

proto MAIN (:$need, Str :$hope) {
# {*}  # If you want to execute the body of the "multi main" stubs, then
uncomment this
  say "I need $need reasons to go on" if $need;
  say "I have $hope" if $hope;
}

multi MAIN (Int :$need!) {}
multi MAIN (Str :$hope!) {}

__END__


And a prettier, less hackish way using dynamic scoping:

#!perl6

multi MAIN (Int :$*need!) { Main }
multi MAIN (Str :$*hope!) { Main }

only Main {
  say "I need $*need reasons to go on" if $*need;
  say "I have $*hope" if $*hope;
}

__END__




-y

On Thu, Jul 2, 2015 at 3:59 PM, Patrick R. Michaud <pmich...@pobox.com>
wrote:

> On Thu, Jul 02, 2015 at 03:22:17PM -0400, Brandon Allbery wrote:
> > On Thu, Jul 2, 2015 at 3:08 PM, Tom Browder <tom.brow...@gmail.com>
> wrote:
> >
> > > 1.  Write the 'main' program as another subroutine and call it from
> > > each of the appropriate multi
> > > subs--aarghh!
> > >
> >
> > This seems like the right one to me; it also makes it easier to provide
> > similar functionality as a library.
>
> This is the approach I would take, yes.
>
> Pm
>

Reply via email to