> This switch statement RFC seems to be built on the premise that the
   > reason to have a switch statement is to remove a common parameter
   > from the following limited form conditional expressions.

Yes. As I point out in the paper, that's the *nature* of a switch statement.
To distribute a test spatially, by factoring.
   
   > However, while the table of 16 different ways in which two values
   > could generate a match is interesting, it can only ever perform at
   > most two operations per pair of types (depending on which type is
   > found in which of the two positions).
   
Not so:

        switch ($value) {
                case 1          {...}           # numeric equality
                case "a"        {...}           # string equality
                case $obj       {...}           # referential equality
                case /pat/      {...}           # pattern match
                case %hash      {...}           # hash lookup
                case [1..10]    {...}           # list inclusion
                case __<100     {...}           # subroutine return
        }

Granted one would rarely want all these at once, but a non-trivial subset
is entirely plausible:

        sub classify {
                switch ($_[0]) {
                        case 0          { return 'zero' }
                        case \&odd      { return 'odd' }
                        case [1..9]     { return 'even' }
                        case /[a-f]/i   { return 'hex' }
                }
        }
        
   
   > I find it unlikely that the casual Perl programmer, and even many
   > expert Perl programmers, will be able to usefully memorize the list
   > of operations proposed for the type pairs. This inability to
   > memorize the list will no doubt curl the corner of the switch page
   > in the perl documentation.

No. The whole point is that they just DWIM.

   
   > I think the fundamental purpose of the switch statement is to
   > choose one (generally) of many cases, and that the factoring of one
   > of the parameters is what gets in the way of having a rich set of
   > matching operations.

Just selecting one from many alternatives is a cascaded if's job.

The defining characteristic of a switch the the factoring of some part
of the comparisons. And it's an important characteristic, because it
focussed the reader's mind on the commonality of the test.


   > Hence, I think it suffices to have a single keyword for switch: not
   > "switch", but "case". The block containing "case" would be the
   > switch statement. "case" is simply a rename of "elsif" whose first
   > occurrence in a block simply pretends to follow "if (0) {}". 

If that's the consensus, let's just have elsif.
But I don't think that's the consensus.

I appreciate your comments, but I certainly intend to push ahead with
the proposed syntax -- as I proposed it. A very large number of people
like it as it is. If I'm wrong, let Larry kill it.

Damian

Reply via email to