lua-users home
lua-l archive

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




On Nov 10, 2007 3:06 AM, Mark Hamburg <mhamburg@adobe.com> wrote:
> match k
>   with 10, 11 then return 1 end
>   with 12 then return 2 end
>   with i if 13<=i and i<=16 then return 4 end
> end

I'm not sure what the last clause means unless it's:

   if k == i and 13 <= i and i <= 16 then ...

which is an interesting extension to standard case behavior. On the other
hand, it then forces sequential testing rather than simply accepting that as
one implementation.

That's presumably what it means: the proposal was a syntax change of metalua's pattern matching, and the original stuff is "<pattern> -> <block>", which can be protected with a guard _expression_ (which can prevent the pattern from matching if it returns false): "<pattern> if <guard-_expression_> -> <block".

Clearly this forces a sequential evaluation, unless onw starts to make the compiler really complex. But the intended use case for pattern matching isn't as a simple switch/case, although it happens to cover that case as well.