Pattern matching as a library

2016-03-12 Thread Simen Kjaeraas via Digitalmars-d
As I once again bemoaned D's lack of pattern matching yesterday, I was inspired to create this[0] implementation, that plays to D's strengths, allows for user-defined matching, and has a fairly usable syntax. The core usage looks like this: unittest { auto a = tuple(1, "foo"); auto b = mat

Re: Pattern matching as a library

2016-03-12 Thread Jacob Carlborg via Digitalmars-d
On 12/03/16 14:12, Simen Kjaeraas wrote: As I once again bemoaned D's lack of pattern matching yesterday, I was inspired to create this[0] implementation, that plays to D's strengths, allows for user-defined matching, and has a fairly usable syntax. The core usage looks like this: unittest {

Re: Pattern matching as a library

2016-03-12 Thread Simen Kjaeraas via Digitalmars-d
On Saturday, 12 March 2016 at 20:56:47 UTC, Jacob Carlborg wrote: On 12/03/16 14:12, Simen Kjaeraas wrote: As I once again bemoaned D's lack of pattern matching yesterday, I was inspired to create this[0] implementation, that plays to D's strengths, allows for user-defined matching, and has a f

Re: Pattern matching as a library

2016-03-13 Thread Simen Kjaeraas via Digitalmars-d
On Sunday, 13 March 2016 at 02:33:49 UTC, Simen Kjaeraas wrote: http://dpaste.dzfl.pl/7360ee90b344 Dammit, 3:30AM was apparently too late, and some bad code leaked through. I managed to sidestep a problem by writing nonsense code. The problem I get can be reduced to this: struct S { voi

Re: Pattern matching as a library

2016-03-13 Thread Jacob Carlborg via Digitalmars-d
On 13/03/16 03:33, Simen Kjaeraas wrote: The match function goes through the list of patterns and for each one asks the tuple if opMatch returns true for that pattern. If it does, the function assigned that pattern is called with the values assigned to args. opMatch here is checking for each el