[nem-en] match on specific parameter

Michal Moskal michal.moskal at gmail.com
Sun Jan 29 08:17:09 CET 2006


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/



More information about the devel-en mailing list