develooper Front page | perl.perl5.porters | Postings from March 2000

Re: What's left to do? [LONG]

From:
Damian Conway
Date:
March 22, 2000 14:18
Subject:
Re: What's left to do? [LONG]
Message ID:
200003222218.JAA06274@indy05.csse.monash.edu.au
    
Tom wrote:

   > >} switch structures
   > 
   > >Everyone wants a switch statement but nobody can agree on the right
   > >way to do it.
   > 
   > There will be something at the Perl Conference regarding this.  I
   > don't feel ethical pre-announcing details of unpublished work not
   > my own, but perhaps the author shall, upon reading this response,
   > choose to offer the group a synopsis, sample, or snapshot of his
   > experiences with this.

I'm the author in question, but I'm not keen to telegraph too much
of the punch before the conference (nor do I want to have to defend
my proposal here until I have raised the unthinking masses behind me ;-)

Here's the abstract of the paper:

	   Where Angels Fear To Tread: A C<switch> Statement for Perl 
	                      Damian Conway

        			Abstract

        This paper proposes a syntax and semantics for an explicit case
        mechanism for Perl. The syntax is minimal, introducing only the
        keywords C<switch> and C<case> and conforming to the general
        pattern of existing Perl control structures. The semantics are
        particularly rich, allowing any one (or more) of nearly 30 forms
        of matching to be used when comparing a switch value with its
        various cases. A prototype implementation of the proposed
        addition is also described.


And here's an example of what you can do with the module:

        %tagline = ( woohoo => 1,  d'oh => 1, 'eat my shorts' => 0 );

        while (<>) {
                switch ($_);

                case %tagline  { print "homer\n"; next }       # if $tagline{$_}
                case /a-z/i    { print "alpha\n"; next }       # if $_ =~ /a-z/i
                case [1..9]    { print "small num\n"; next }   # if 1<=$_<=9

                case { $_[0] >= 10 }                           # if $_ >= 10
		{
                        my $age = <>;
                        switch __ < $age;

                        case 20  { print "teens\n"; next }     # if 20 < $age
                        case 30  { print "twenties\n"; next }  # if 30 < $age
                        else     { print "history\n"; next }
                }

                print "aha\n" case 42;                         # if $_ == 42
                print "huh\n" case '?';                        # if $_ eq '?'
        }


The "how" and "why" I will defer until the Perl Conference.

Damian




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