lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Nov 7, 2007 12:52 PM, Fabien <fleutot+lua@gmail.com> wrote:
> match k with
> | 10 | 11 -> return 1
> | 12 -> return 2
> | i if 13<=i and i<=16 -> return 4
> end

The variable match syntax is nice and very general. My only concern is
that the pipe character tends to have other associations. Is it
Lua-ish?

> - 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[1], c[2])
> end
>
> would print "1st part: abc; 2nd part: 123".

I like this regex match....

steve d.