Re: Operator overloading or alternatives to expression templates

2015-09-17 Thread Timon Gehr via Digitalmars-d
On 09/15/2015 06:53 PM, Andrei Alexandrescu wrote: On 09/14/2015 03:35 PM, Timon Gehr wrote: On 09/14/2015 08:09 PM, Andrei Alexandrescu wrote: On 09/13/2015 10:06 AM, Martin Nowak wrote: ... - language regularization It's surprising to find these "arbitrary" language limitations. The

Re: Operator overloading or alternatives to expression templates

2015-09-15 Thread Andrei Alexandrescu via Digitalmars-d
On 09/14/2015 03:35 PM, Timon Gehr wrote: On 09/14/2015 08:09 PM, Andrei Alexandrescu wrote: On 09/13/2015 10:06 AM, Martin Nowak wrote: ... - language regularization It's surprising to find these "arbitrary" language limitations. The non-predictability of what's possible has always

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread burjui via Digitalmars-d
On Sunday, 13 September 2015 at 17:16:40 UTC, Daniel N wrote: int opCmp(Foo rhs) { return (id > rhs.id) - (id < rhs.id); } IMO, subtracting boolean values is bad code style, it's better to be explicit about your intention: (id > rhs.id ? 1 : 0) - (id < rhs.id ? 1 : 0)

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Sebastiaan Koppe via Digitalmars-d
On Friday, 11 September 2015 at 19:41:41 UTC, Martin Nowak wrote: Does anyone have a different idea how to make a nice query language? db.get!Person.where!(p => p.age > 21 && p.name == "Peter") In our last project we took the following approach: `auto q =

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread jmh530 via Digitalmars-d
On Friday, 11 September 2015 at 19:41:41 UTC, Martin Nowak wrote: AFAIK expression templates are the primary choice tom implement SIMD and matrix libraries. And I still have [this idea](http://dpaste.dzfl.pl/cd375ac594cf) of implementing a nice query language for ORMs. While expression

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Martin Nowak via Digitalmars-d
On 09/14/2015 03:47 PM, Sebastiaan Koppe wrote: > > In our last project we took the following approach: > > `auto q = query.builder!Person.age!">"(20).name("Peter");` Interesting idea.

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Sebastiaan Koppe via Digitalmars-d
On Monday, 14 September 2015 at 18:17:05 UTC, Adam D. Ruppe wrote: On Monday, 14 September 2015 at 13:47:10 UTC, Sebastiaan Koppe wrote: `auto q = query.builder!Person.age!">"(20).name("Peter");` I confess that I'm not really paying attention to this thread, but I can't help but think plain

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Andrei Alexandrescu via Digitalmars-d
On 09/13/2015 10:06 AM, Martin Nowak wrote: On 09/13/2015 05:03 AM, Andrei Alexandrescu wrote: Yah, understood. Problem here is the approach is bound to run into walls at every few steps. Say you fix the comparisons to work. Then you have operators such as LIKE that are necessary yet not

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Andrei Alexandrescu via Digitalmars-d
On 09/13/2015 01:16 PM, Daniel N wrote: On Sunday, 13 September 2015 at 14:06:46 UTC, Martin Nowak wrote: struct Foo { size_t id; int opCmp(Foo rhs) { if (id < rhs.id) return -1; if (id == rhs.id) return 0; else return 1; } bool

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Adam D. Ruppe via Digitalmars-d
On Monday, 14 September 2015 at 13:47:10 UTC, Sebastiaan Koppe wrote: `auto q = query.builder!Person.age!">"(20).name("Peter");` I confess that I'm not really paying attention to this thread, but I can't help but think plain old literal: `Person.age > 20 && Person.name = 'Peter'` is nicer.

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Andrei Alexandrescu via Digitalmars-d
On 09/13/2015 03:06 PM, Martin Nowak wrote: On 09/13/2015 07:16 PM, Daniel N wrote: Could you try this? int opCmp(Foo rhs) { return (id > rhs.id) - (id < rhs.id); } That's not the point, opCmp requires twice as many comparisons as needed for <. If they are more expansive, e.g. string

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Andrei Alexandrescu via Digitalmars-d
On 09/14/2015 07:32 AM, burjui wrote: On Sunday, 13 September 2015 at 17:16:40 UTC, Daniel N wrote: int opCmp(Foo rhs) { return (id > rhs.id) - (id < rhs.id); } IMO, subtracting boolean values is bad code style I love it! -- Andrei

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Timon Gehr via Digitalmars-d
On 09/14/2015 08:09 PM, Andrei Alexandrescu wrote: On 09/13/2015 10:06 AM, Martin Nowak wrote: ... - language regularization It's surprising to find these "arbitrary" language limitations. The non-predictability of what's possible has always been a huge issue for me with C++, i.e. you

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Ola Fosheim Grøstad via Digitalmars-d
On Monday, 14 September 2015 at 19:35:39 UTC, Timon Gehr wrote: Furthermore, having arbitrary designed-in irregularities is not comparable to implementing a system whose emergent behavior is not understood sufficiently well. (D is guilty of both, but the former is much easier to fix than the

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread Timon Gehr via Digitalmars-d
On 09/14/2015 08:18 PM, Andrei Alexandrescu wrote: On 09/13/2015 01:16 PM, Daniel N wrote: On Sunday, 13 September 2015 at 14:06:46 UTC, Martin Nowak wrote: struct Foo { size_t id; int opCmp(Foo rhs) { if (id < rhs.id) return -1; if (id == rhs.id)

Re: Operator overloading or alternatives to expression templates

2015-09-14 Thread deadalnix via Digitalmars-d
On Monday, 14 September 2015 at 18:24:00 UTC, Andrei Alexandrescu wrote: On 09/14/2015 07:32 AM, burjui wrote: On Sunday, 13 September 2015 at 17:16:40 UTC, Daniel N wrote: int opCmp(Foo rhs) { return (id > rhs.id) - (id < rhs.id); } IMO, subtracting boolean values is bad code style I

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Sönke Ludwig via Digitalmars-d
Am 11.09.2015 um 21:40 schrieb Martin Nowak: I find the reasons for turining down my ER a bit moot. [Issue 14593 – operator overloading can't be used with expression templates](https://issues.dlang.org/show_bug.cgi?id=14593) (...) The missing support for overloading the individual relational

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Ola Fosheim Grøstad via Digitalmars-d
On Sunday, 13 September 2015 at 03:03:44 UTC, Andrei Alexandrescu wrote: Yah, understood. Problem here is the approach is bound to run into walls at every few steps. Say you fix the comparisons to work. Then you have operators such as LIKE that are necessary like(Person.Name,"peter%")

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread deadalnix via Digitalmars-d
On Sunday, 13 September 2015 at 03:03:44 UTC, Andrei Alexandrescu wrote: On 09/12/2015 04:08 PM, Martin Nowak wrote: On Friday, 11 September 2015 at 23:47:42 UTC, Andrei Alexandrescu wrote: 1. Use lambdas, which seem to already do what you want: db.get!Person.filter!(p => p.age > 21 && p.name

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Dicebot via Digitalmars-d
I am pretty sure I'd prefer hygienic string DSL (with explicit alias list for used context symbols, like in Diet) over LINQ-like magic.

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Jack Stouffer via Digitalmars-d
On Saturday, 12 September 2015 at 22:38:53 UTC, Bahman Movaqar wrote: Django's approach is, IMO, the cleverest and least magical one while keeping it expressive and efficient: Person.objects.filter(age__gt=21, name__eq='peter') As the main examples in this thread are for ORMs, I think

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 03:15 PM, Jack Stouffer wrote: > > I know that this effect is much harder to create in a explicitly and > strongly typed language, but I just wanted to show a real world example > of how these could be used to great effect. But it is doable in D, and even better it's possible to

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Jack Stouffer via Digitalmars-d
On Sunday, 13 September 2015 at 14:06:46 UTC, Martin Nowak wrote: - logical indexing x[x < 20] e.g. opBinary!"<" returns a bit mask to select entries of a large vector Oh yes please! This is one of the more powerful features of numpy.

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 05:03 AM, Andrei Alexandrescu wrote: > Yah, understood. Problem here is the approach is bound to run into walls > at every few steps. Say you fix the comparisons to work. Then you have > operators such as LIKE that are necessary yet not representable in D. So > more tricks are in

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 11:00 AM, Sönke Ludwig wrote: > I had played around with some ideas for a similar project, but didn't > find a really satisfying solution: > https://github.com/rejectedsoftware/dotter/blob/11ec72325e76c3329a58545526940c1df5328a2d/source/dotter/orm.d#L320 Yeah, that doesn't look too

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Martin Nowak via Digitalmars-d
On 09/13/2015 07:16 PM, Daniel N wrote: > > Could you try this? > > int opCmp(Foo rhs) > { > return (id > rhs.id) - (id < rhs.id); > } That's not the point, opCmp requires twice as many comparisons as needed for <. If they are more expansive, e.g. string comparison, your trick won't work.

Re: Operator overloading or alternatives to expression templates

2015-09-13 Thread Daniel N via Digitalmars-d
On Sunday, 13 September 2015 at 14:06:46 UTC, Martin Nowak wrote: struct Foo { size_t id; int opCmp(Foo rhs) { if (id < rhs.id) return -1; if (id == rhs.id) return 0; else return 1; } bool opBinary(string s:"<")(Foo rhs) {

Re: Operator overloading or alternatives to expression templates

2015-09-12 Thread Bahman Movaqar via Digitalmars-d
On Fri, 11 Sep 2015 21:40:58 +0200, Martin Nowak wrote: Does anyone have a different idea how to make a nice query language? db.get!Person.where!(p => p.age > 21 && p.name == "Peter") Django's approach is, IMO, the cleverest and least magical one while keeping

Re: Operator overloading or alternatives to expression templates

2015-09-12 Thread Martin Nowak via Digitalmars-d
On Friday, 11 September 2015 at 23:47:42 UTC, Andrei Alexandrescu wrote: 1. Use lambdas, which seem to already do what you want: db.get!Person.filter!(p => p.age > 21 && p.name == "Peter") The way this'd go, the db.get!Person() call returns an input range of Person. Presumably introspection

Re: Operator overloading or alternatives to expression templates

2015-09-12 Thread Dmitry Olshansky via Digitalmars-d
On 12-Sep-2015 23:08, Martin Nowak wrote: On Friday, 11 September 2015 at 23:47:42 UTC, Andrei Alexandrescu wrote: 1. Use lambdas, which seem to already do what you want: db.get!Person.filter!(p => p.age > 21 && p.name == "Peter") The way this'd go, the db.get!Person() call returns an input

Re: Operator overloading or alternatives to expression templates

2015-09-12 Thread Martin Nowak via Digitalmars-d
On Friday, 11 September 2015 at 23:19:54 UTC, Timon Gehr wrote: Does anyone have a different idea how to make a nice query language? db.get!Person.where!(p => p.age > 21 && p.name == "Peter") You could give up on operator syntax. That's what I did in the prototype, p.age.gt(21), but it's

Re: Operator overloading or alternatives to expression templates

2015-09-12 Thread Andrei Alexandrescu via Digitalmars-d
On 09/12/2015 04:08 PM, Martin Nowak wrote: On Friday, 11 September 2015 at 23:47:42 UTC, Andrei Alexandrescu wrote: 1. Use lambdas, which seem to already do what you want: db.get!Person.filter!(p => p.age > 21 && p.name == "Peter") The way this'd go, the db.get!Person() call returns an input

Re: Operator overloading or alternatives to expression templates

2015-09-12 Thread Jacob Carlborg via Digitalmars-d
On 2015-09-12 01:47, Andrei Alexandrescu wrote: There's two canonical ways to do that. 1. Use lambdas, which seem to already do what you want: db.get!Person.filter!(p => p.age > 21 && p.name == "Peter") The way this'd go, the db.get!Person() call returns an input range of Person. Presumably

Re: Operator overloading or alternatives to expression templates

2015-09-12 Thread Jacob Carlborg via Digitalmars-d
On 2015-09-11 21:40, Martin Nowak wrote: I find the reasons for turining down my ER a bit moot. [Issue 14593 – operator overloading can't be used with expression templates](https://issues.dlang.org/show_bug.cgi?id=14593) AFAIK expression templates are the primary choice tom implement SIMD and

Re: Operator overloading or alternatives to expression templates

2015-09-12 Thread via Digitalmars-d
On Friday, 11 September 2015 at 19:41:41 UTC, Martin Nowak wrote: Does anyone have a different idea how to make a nice query language? db.get!Person.where!(p => p.age > 21 && p.name == "Peter") Do it at runtime?

Operator overloading or alternatives to expression templates

2015-09-11 Thread Martin Nowak via Digitalmars-d
I find the reasons for turining down my ER a bit moot. [Issue 14593 – operator overloading can't be used with expression templates](https://issues.dlang.org/show_bug.cgi?id=14593) AFAIK expression templates are the primary choice tom implement SIMD and matrix libraries. And I still have [this

Re: Operator overloading or alternatives to expression templates

2015-09-11 Thread Jonathan M Davis via Digitalmars-d
On Friday, 11 September 2015 at 19:41:41 UTC, Martin Nowak wrote: Does anyone have a different idea how to make a nice query language? db.get!Person.where!(p => p.age > 21 && p.name == "Peter") Don't the suggestions for DSLs generally revolve around using string mixins to use whatever syntax

Re: Operator overloading or alternatives to expression templates

2015-09-11 Thread Timon Gehr via Digitalmars-d
On 09/11/2015 09:40 PM, Martin Nowak wrote: I find the reasons for turining down my ER a bit moot. ... +1. [Issue 14593 – operator overloading can't be used with expression templates](https://issues.dlang.org/show_bug.cgi?id=14593) AFAIK expression templates are the primary choice tom

Re: Operator overloading or alternatives to expression templates

2015-09-11 Thread H. S. Teoh via Digitalmars-d
On Fri, Sep 11, 2015 at 07:47:42PM -0400, Andrei Alexandrescu via Digitalmars-d wrote: > On 09/11/2015 03:40 PM, Martin Nowak wrote: > >I find the reasons for turining down my ER a bit moot. > > > >[Issue 14593 – operator overloading can't be used with expression >

Re: Operator overloading or alternatives to expression templates

2015-09-11 Thread Andrei Alexandrescu via Digitalmars-d
On 09/11/2015 08:03 PM, H. S. Teoh via Digitalmars-d wrote: Needless to say, I did not have the patience (nor persistence!) to decipher those error messages; most of my efforts lay in copying textbook examples from the documentation and modifying them piece by piece, checking their compilability

Re: Operator overloading or alternatives to expression templates

2015-09-11 Thread deadalnix via Digitalmars-d
On Saturday, 12 September 2015 at 00:27:45 UTC, Andrei Alexandrescu wrote: On 09/11/2015 08:03 PM, H. S. Teoh via Digitalmars-d wrote: Needless to say, I did not have the patience (nor persistence!) to decipher those error messages; most of my efforts lay in copying textbook examples from the

Re: Operator overloading or alternatives to expression templates

2015-09-11 Thread Andrei Alexandrescu via Digitalmars-d
On 09/11/2015 03:40 PM, Martin Nowak wrote: I find the reasons for turining down my ER a bit moot. [Issue 14593 – operator overloading can't be used with expression templates](https://issues.dlang.org/show_bug.cgi?id=14593) AFAIK expression templates are the primary choice tom implement SIMD