[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Switch/Case statements revisited
- From: "steve donovan" <steve.j.donovan@...>
- Date: Wed, 7 Nov 2007 15:24:34 +0200
On Nov 7, 2007 12:52 PM, Fabien <email@example.com> wrote:
> match k with
> | 10 | 11 -> return 1
> | 12 -> return 2
> | i if 13<=i and i<=16 -> return 4
The variable match syntax is nice and very general. My only concern is
that the pipe character tends to have other associations. Is it
> - a table matches if every field in the pattern matches the corresponding
> field in k, which must obviously be a table (I'm simplifying a bit here but
> that's basically the idea)
That's starting to get complicated. The rules must be obvious. And
what if that table redefined equality properly, and we matched it
against an instance of the same class?
> match "abc123" with
> | c/"^([a-z]+)([0-9]*)$" -> printf("1st part: %s; 2nd part: %s", c, c)
> would print "1st part: abc; 2nd part: 123".
I like this regex match....