[nem-en] match on specific parameter

Philippe Quesnel philippe.quesnel at gmail.com
Sun Jan 29 10:01:54 CET 2006


I agree (to both)

I remember thinking "this is useless, I have to write match(xxx) anyways"
;-)

& I prefer 'match lst' to just 'match'.

On 1/29/06, Michal Moskal <michal.moskal at gmail.com> wrote:
>
> Hi,
>
> I was wondering about an additional feature. Now it is possible to
> match on all function parameters without the 'match' construction, i.e.
>
> def foo (x)
>   | ...
>   | ...
>
> is the equivalent to:
>
> def foo (x)
>   match (x)
>     | ...
>     | ...
>
> it also works for multiple parameters:
>
> def foo (a,b,c)
>   | ...
>
> ====>
>
> def foo (a,b,c)
>   match  ((a,b,c))
>     | ...
>
> However in most cases you only want to match on a single parameter
> (at least I do), so you end up writing:
>
> def rev (acc, lst)
>   match (lst)
>     | x :: xs => rev (x :: acc, xs)
>     | [] => acc
>
> Granted you could have used:
>
> def rev (_)
>   | (acc, x :: xs) => rev (x :: acc, xs)
>   | (acc, []) => acc
>
> But I personally don't find it very readable. I would like something
> like:
>
> def rev (acc, match lst)
>   | x :: xs => rev (x :: acc, xs)
>   | [] => acc
>
> or maybe "def rev (acc, match)". I'm not sure about the syntax.
>
> What do you think?
>
> On a related note, d proposed on IRC, that we could transform:
>
> foo () : ...
>   | ...
>
> inside classes and variants to:
>
> foo () : ...
>   match (this)
>     | ...
>
> which I think also makes sense.
> --
>    Michal Moskal,
>    http://nemerle.org/~malekith/
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman/pipermail/devel-en/attachments/20060129/05fb7001/attachment.html


More information about the devel-en mailing list