I was playing around with a Perl 6 implementation of a command-line program that takes several switches. The signature to MAIN
was quite involved and a bit messy. I wondered if there was a way to define the signature somewhere else and tell the subroutine what to use:
# possibly big and messy signature
my $sig;
BEGIN { $sig = :( Int $n, Int $m ) };
multi MAIN ( $sig ) {
put "Got $n and $m";
}
MAIN
doesn't see the variables in the signature even though the signature is set before MAIN
compiles:
===SORRY!=== Error while compiling /Users/brian/Desktop/signature.p6
Variable '$n' is not declared
at /Users/brian/Desktop/signature.p6:7
I figured this sort of thing might be handy for generating methods after compile time and selecting signatures based on various factors.