<div class="gmail_quote">On Wed, Jan 13, 2010 at 1:55 PM, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:andrei@erdani.com">andrei@erdani.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="im">Sean Kelly wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">It's worth adding that Erlang does provide pattern matching capabilities that have to be a run time in D, but I'm not sure this same capability is available in Scala, for example. In our case, this will probably be handled manually by the user, with possibly some fancier way to do it later (metaprogramming can do quite a lot in D). For example:<br>
<br> receive(<br> (int x) { ... },<br> (string a, int b) { if (a == "blah") return false; ...; return true; }<br> );<br><br>Here, the second function checks string a to see if it matches a pattern, and returns true/false to indicate that there was a match.<br>
</blockquote><br></div>For the OO crowd, I think this will be quite useful:<br><br>class Handler<br>{<br> bool receive(int x) { ... }<br> bool receive(int x, double y) { ... }<br> bool receive(string s, int x) { ... }<br>
...<br>}<br><br>auto h1 = new Handler;<br>auto h2 = new Handler;<br>receive(h1, h2); // dispatches automatically<br> // starting from h1<br><br>Sean, may I put this in confidence that you'll find the time to implement it? Walter, we may need some introspection chops for that too.<br>
<font color="#888888"><br><br>Andrei</font> </blockquote>
<div> </div></div>
<div>Also, what does it mean?</div>
<div> </div>
<div>If I do this syntax:</div>
<div> </div>
<div>
<div>auto dg1 = void delegate(A x) { ... };
<div>auto dg2 = void delegate(B x) { ... };</div>
<div> </div>
<div>receive(dg1, dg2);</div>
<div> </div>
<div>Does this mean receive anything that matches dg1, and if nothing is found, receive anything that matches dg2? Or does it mean to take the first message in order that matches either one?</div>
<div> </div></div></div>
<div>Kevin</div>
<div> </div>
<div> </div>