Re: pattern matching on fields of the argument

Daniel Bonniot <[email protected]> Mon, 02 Aug 2004 15:47:38 +0200
Newsgroups gmane.comp.lang.nice.devel
Message-ID <[email protected]>
> Basically I want to do some tree transformations, and it makes more
> sense to group the code by transformation rather than grouping by
> "shared prefix".

Yes, it makes sense.

> Ideally the nice code would look something vaguely like
> 
>   class Foo { ?Foo a; int b; }
> 
>   void foo(Foo f);
>   foo(Foo(a:null)) = ...

What about allowing an optional boolean condition in method 
implementations? Something like:

foo(Foo f) if (f.a == null) = ...

It's more verbose, but also more expressive. For example, you can have 
conditions involving several parameters together:

foo(int x, int y) if (x < y)
{ ... }

Another advantage is that I think it should be much simpler to 
implement. Trivial change to the parser. bossa.syntax.Pattern would have 
an additional slot for the condition. When comparing patterns, the 
presence of a condition would need to be taken into account. Then when 
generating dispatch code, additionally test that the condition holds.

Would this version suit your needs well enough?

To guide you for an implementation, it might be practical to meet on the 
IRC channel.

Daniel


-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com