November 21, 2009
Walter Bright pisze:
> Don wrote:
>> There's not many sensible operators anyway. opPow is the only missing one that's present in many other general-purpose languages. The only other ones I think are remotely interesting are dot and cross product.
> 
> Yup.
> 
>> Anything beyond that, you generally want a full DSL, probably with different precendence and associativity rules. Eg, for regexp, you'd want postfix * and + operators. There are examples of clever things done in C++  with operator overloading, but I think that's just because it's the only way to do DSLs in C++.
> 
> I was enthralled with the way C++ did it for regex for a while, but when I think more about it, it's just too clever. I think it's more operator overloading abuse now.
> 
>> I don't think the applications are there.
> 
> I agree.

Well, I can understand your fear about operator abuse. And I agree that code might be awful when operator overloading will be abused.

But I have in mind one very convincing example. I defined in D/Java SQL syntax. They are also other frameworks which do the same.

What can I say about my experiences with using such framework: it is very, very powerful concept. It cuts time necessary to develop application, makes sql statements type safe and allows to pass around parts of sql statements inside application. It also makes easy refactoring of sql statement (especially in Java). Its huge win comparing it to defining DSL as strings.

It's hard to explain just in few sentences all details. I have already done it long time ago, and in my first post I provided links.

Problem with current approach is that I have to define SQL in D/Java in following way:

auto statement = Select(visitcars.name).Where(And(More(visitcards.id, 100), Like(visitcards.surname, "A*")));

Please look at code in Where(). It's so awfuuuuulllllll!

It would be so much better to write:
auto statement = Select(visitcars.name).Where((visitcards.id `>` 100) `AND` (visitcards.surname `Like` "A*"));

I used here syntax which you have proposed with delimiter ``. I think it is good enough solution for such purpose.

But please, don't underestimate problem! Many DSL languages would never appear if languages would be good enough.

As I said solution with delimiter is good enough for me. It has another advantage that it clearly shows in code that you have overloaded operator here, so no surprises here. Additionally when you implement template function:
opInfix('AND')(val0, val1);
you pass string into template. So I see it quite intuitive that you use string as operator: ``. Maybe there will be not necessary to change current behavior that `` defines string.

I think we have good possibility to  open this door now. It can be even implemented later, but I would wish just not to close this door now :-)

BR
Marcin Kuszczak
(aarti_pl)
November 22, 2009
On Sat, 21 Nov 2009 13:21:10 -0500, aarti_pl <aarti@interia.pl> wrote:
> [snip]
>
> Problem with current approach is that I have to define SQL in D/Java in following way:
>
> auto statement = Select(visitcars.name).Where(And(More(visitcards.id, 100), Like(visitcards.surname, "A*")));
>
> Please look at code in Where(). It's so awfuuuuulllllll!
>
> It would be so much better to write:
> auto statement = Select(visitcars.name).Where((visitcards.id `>` 100) `AND` (visitcards.surname `Like` "A*"));
>
> I used here syntax which you have proposed with delimiter ``. I think it is good enough solution for such purpose.
>
> [snip]

Would something like expression trees (http://msdn.microsoft.com/en-us/library/bb397951.aspx) suit your needs?
November 23, 2009
On Thu, 19 Nov 2009 13:54:04 -0500, dsimcha <dsimcha@yahoo.com> wrote:

> The hook doesn't sound like a bad idea, but it raises a lot of issues with the
> implementation details.  These are things I could figure out given plenty of time.
>  I'd like weak refs, too.  However, I don't think this makes the short list for D2
> because:
>
> 1.  Doing it at all properly requires a lot of thought about what a good design
> for such an API should be and how to implement it efficiently.

To have a hook or not to have a hook is not as important as fixing the bug.  If we do it first without a public hook, that is fine, then we can refine it later.

>
> 2.  I think we still need an ArrayBuilder or something because, while the MRU
> would be reasonably efficient, it still wouldn't be as efficient as an
> ArrayBuilder, and would do nothing to solve the uniqueness problem.  Therefore, I
> think fleshing out ArrayBuilder is a higher priority.

Let's fix the bug first, then we can worry about efficiency.  The fact that you can stomp on immutable memory in safeD is no good for D2.

-Steve
November 24, 2009
how about opLimit ?
November 24, 2009
On Tue, 24 Nov 2009 14:00:18 +0300, Gerrit Wichert <gw@green-stores.de> wrote:

> how about opLimit ?

I recall that Visual Basic has UBound function that returns upper bound of a multi-dimensional array:

Dim a(100, 5, 4) As Byte

UBound(a, 1) -> 100
UBound(a, 2) -> 5
UBound(a, 3) -> 4

Works for single-dimensional arrays, too:

Dim b(8) As Byte
UBound(b) -> 8
November 24, 2009
Denis Koroskin wrote:
> On Tue, 24 Nov 2009 14:00:18 +0300, Gerrit Wichert <gw@green-stores.de> wrote:
> 
>> how about opLimit ?
> 
> I recall that Visual Basic has UBound function that returns upper bound of a multi-dimensional array:
> 
> Dim a(100, 5, 4) As Byte
> 
> UBound(a, 1) -> 100
> UBound(a, 2) -> 5
> UBound(a, 3) -> 4
> 
> Works for single-dimensional arrays, too:
> 
> Dim b(8) As Byte
> UBound(b) -> 8

See the length property.

char[] a = "Hello, World!";  // a.length = 13
November 25, 2009
On Wed, 25 Nov 2009 00:46:39 +0300, Travis Boucher <boucher.travis@gmail.com> wrote:

> Denis Koroskin wrote:
>> On Tue, 24 Nov 2009 14:00:18 +0300, Gerrit Wichert <gw@green-stores.de> wrote:
>>
>>> how about opLimit ?
>>  I recall that Visual Basic has UBound function that returns upper bound of a multi-dimensional array:
>>  Dim a(100, 5, 4) As Byte
>>  UBound(a, 1) -> 100
>> UBound(a, 2) -> 5
>> UBound(a, 3) -> 4
>>  Works for single-dimensional arrays, too:
>>  Dim b(8) As Byte
>> UBound(b) -> 8
>
> See the length property.
>
> char[] a = "Hello, World!";  // a.length = 13

Thanks, but... This thread is actually about discussing different names for a $ operator. I brought a point that VB has a UBound function that does exactly what opDollar is supposed to do, so something like opUpperBound() might fit.
November 25, 2009
Denis Koroskin wrote:
>>>  I recall that Visual Basic has UBound function that returns upper bound of a multi-dimensional array:
>>>  Dim a(100, 5, 4) As Byte
>>>  UBound(a, 1) -> 100
>>> UBound(a, 2) -> 5
>>> UBound(a, 3) -> 4
>>>  Works for single-dimensional arrays, too:
>>>  Dim b(8) As Byte
>>> UBound(b) -> 8

> I brought a point that VB has a UBound function that does exactly what opDollar is supposed to do, so something like opUpperBound() might fit.

Finally, a viable alternative to opDollar! I could live with
opUpperBound.
November 25, 2009
On 11/25/2009 10:46 AM, Don wrote:
> Denis Koroskin wrote:
>>>> I recall that Visual Basic has UBound function that returns upper
>>>> bound of a multi-dimensional array:
>>>> Dim a(100, 5, 4) As Byte
>>>> UBound(a, 1) -> 100
>>>> UBound(a, 2) -> 5
>>>> UBound(a, 3) -> 4
>>>> Works for single-dimensional arrays, too:
>>>> Dim b(8) As Byte
>>>> UBound(b) -> 8
>
>> I brought a point that VB has a UBound function that does exactly what
>> opDollar is supposed to do, so something like opUpperBound() might fit.
>
> Finally, a viable alternative to opDollar! I could live with
> opUpperBound.

<nitpick>

VB's ubound doesn't do exactly the same thing as $; in your code snippet

b(0)
b(8)

are both valid elements.

Does opUpperBound imply an opLowerBound?

In VB you can declare things like

dim a(20 to 100, 5, 1 to 4) as Byte

LBound(a,1) -> 20

Yep. Visual Basic. Awesome language. *Cough*
November 25, 2009
On Wed, 25 Nov 2009 21:11:48 +0300, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:

> On 11/25/2009 10:46 AM, Don wrote:
>> Denis Koroskin wrote:
>>>>> I recall that Visual Basic has UBound function that returns upper
>>>>> bound of a multi-dimensional array:
>>>>> Dim a(100, 5, 4) As Byte
>>>>> UBound(a, 1) -> 100
>>>>> UBound(a, 2) -> 5
>>>>> UBound(a, 3) -> 4
>>>>> Works for single-dimensional arrays, too:
>>>>> Dim b(8) As Byte
>>>>> UBound(b) -> 8
>>
>>> I brought a point that VB has a UBound function that does exactly what
>>> opDollar is supposed to do, so something like opUpperBound() might fit.
>>
>> Finally, a viable alternative to opDollar! I could live with
>> opUpperBound.
>
> <nitpick>
>
> VB's ubound doesn't do exactly the same thing as $; in your code snippet
>
> b(0)
> b(8)
>
> are both valid elements.
>
> Does opUpperBound imply an opLowerBound?
>
> In VB you can declare things like
>
> dim a(20 to 100, 5, 1 to 4) as Byte
>
> LBound(a,1) -> 20
>
> Yep. Visual Basic. Awesome language. *Cough*

Lower bound is always 0 in D, unlike VB where is can take an arbitrary value. As such, there is no need for opLowerBound in D.