Damian Conway wrote:
> http://www.csse.monash.edu.au/~damian/TPC/2000/switch/paper.txt
Curried operators might be a nice way of generalizing the switch
syntax. When we write:
switch ($x ==) {
1: "one";
2: "two";
3: "three";
}
That could be interpreted as currying the == operator:
my $f = curry($x ==);
And applying it in a cascaded if:
if (&$f(1)) { "one" }
elsif (&$f(2)) { "two" }
else (&$f(3)) { "three" }
If the switch allowed both left and right hand curry operators,
then this would work easily too:
switch (=~ /$pattern/) {
$x: ...;
$y: ...;
$z: ...;
}
And if the cases could be curried:
switch ($x) {
ref: ...;
== 2: ...;
=~ /blah/: ...;
}
And if both arguments to an operator could be curried:
switch ($x, $y) {
<: ...;
==: ...;
>: ...;
}
This seems like it would provide a bit of unification between the
proposed reduce operator and the switch. The curry() operator is
basically just a heavily optimized sub { }. IMHO it makes sense to
provide this because I doubt if closures will ever be cheap/fast
enough to implement switch.
- Ken