[nem-en] literal pattern matching
Michal Moskal
malekith at pld-linux.org
Fri Sep 24 10:35:57 CEST 2004
On Fri, Sep 24, 2004 at 10:07:14AM +0200, Wiktor Zychla wrote:
> would it ever be possible to match "by value" with bound variables? I think
> that this could be ellegant and what's important - superior to C# where you
> cannot use variables in case branches.
As Qrczak said -- it would be unclear if you're bounding variable or
using the previously bound one. We use upper/lowercase rule for this
now. However similar effect can be achieved with 'when' clause:
[...]
> class Hello
> {
> static Foo (n : int, k : int) : string {
> match (n) {
> | k => "equal to k";
| x when x == k => "equal to k"
> | 0 => "null"
> | 1 => "one"
> | 2 => "two"
> | 3 => "three"
> | _ => "more"
> }
> }
--
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: When in doubt, use brute force. -- Ken Thompson :: UL++++$ C++ E--- a?
More information about the devel-en
mailing list