www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Additional Binary Operators

reply "Paul D. Anderson" <paul.d.removethis.anderson comcast.andthis.net> writes:
Operator overloading in D is straightforward and sensible.

I think there is an opportunity for D to do better with some very 
small changes.

I propose including additional Unicode mathematical symbols as 
recognized operators for opBinary. All that would be required is 
to extend the lexer to recognize the symbols as binary operators.

For example, in vector arithmetic there are two different 
products defined -- the dot product and the cross product. Most 
implementations I've seen overload '*' for the inner product, but 
omit operator for the cross product. In UTF-8 the "middle dot", 
('•', \u00B7) and "multiplication sign", ('×', \u00D7), 
correspond to the more usual mathematical notation for the dot 
and cross products, respectively.

UTF-16 has many more mathematical symbols, particularly on the 
2200-22FF and 2A00-2AFF code pages. \u2207 is a wedge, commonly 
used for outer products. The circled plus (u\2A01) and circled 
times sign (\2A02) are defined for some mathematical operations. 
\u2A33 is the "smash product" symbol, which I've never heard of 
before but it sounds cool.

I am NOT suggesting that we include ALL these mathematical 
symbols as operators. If it was up to me I'd include just the 
middle dot, the cross product and the wedge product, but YMMV.

These new operators would need a precedence. Since most of these 
are product operators the precedence should be the same as '*' or 
"/".

Pros:
1. Extends the capability to define mathematical operators for 
user-defined types
2. Shouldn't break any existing code since the symbols aren't 
valid chars in identifiers (as far as I can tell) and aren't 
being used elsewhere.
3. Takes advantage of the existing opBinary overloading so 
implementation should be straightforward.

Cons:
1. They are hard to type or otherwise enter in to a text file.
2. They may not display correctly in some output forms.
3. They could be confusing to someone unfamiliar with the concept.

With regard to the difficulty of entering or displaying these 
characters, I think that is largely because modern computer 
languages only give lip service to Unicode -- code is almost 
exclusively written in ASCII. I have seen one instance where a 
certain mathematical constant was named 'π', but the author was 
an iconoclast and pariah.
Mar 01 2013
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Paul D. Anderson:

 I am NOT suggesting that we include ALL these mathematical 
 symbols as operators. If it was up to me I'd include just the 
 middle dot, the cross product and the wedge product, but YMMV.

If you want to introduce new standard operators, I suggest to keep their number very low. And I suggest to avoid Unicode symbols. The operators I find useful for me are one more product operator, a max infix operator and a min infix operator. Maybe #* #max #min? (Also usable with a "=" prefix, #=* #=max #=min). Bye, bearophile
Mar 01 2013
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/3/13 9:42 AM, Manu wrote:
 GCC has min and max operators, and the syntax is very clever:
    min = a <? b;
    max = a >? b;
 Ie, a shorthand of the ?: operator, in a similar way that C# has '??'
 (another really nice shorthand).

Gone. http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html Andrei
Mar 03 2013
prev sibling next sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 03/01/2013 01:51 PM, Paul D. Anderson wrote:

 In UTF-8 the "middle dot", ('•', \u00B7) and
 "multiplication sign", ('×', \u00D7)

[...]
 UTF-16 has many more mathematical symbols

Sorry to pick on this unrelated issue but UTF-8 and UTF-16 are just Unicode encodings. Unicode itself defines all of those characters and they can all be represented in any encoding. Ali
Mar 01 2013
parent Tony <askme nospam.net> writes:
In article <kgr8ub$1nc7$1 digitalmars.com>, acehreli yahoo.com says...
 
 On 03/01/2013 01:51 PM, Paul D. Anderson wrote:
 
  > In UTF-8 the "middle dot", ('•', \u00B7) and
  > "multiplication sign", ('×', \u00D7)
 
 [...]
 
  > UTF-16 has many more mathematical symbols
 
 Sorry to pick on this unrelated issue but UTF-8 and UTF-16 are just 
 Unicode encodings. Unicode itself defines all of those characters and 
 they can all be represented in any encoding.
 
 Ali

Unicode is indeed an encoding. Same for ASCII, EBCDIC, ISO 8859-X, FIELDATA, etc. The clue is in the name and term: UniCODE and enCODEing. The CODEs are unique numbers associated with each character. UTF-Xs are transformation formats. While it is not strictly incorrect to call the UTFs encodings, it is probably best avoided for better clarity. The use of the word "encoding" to mean "coded character set" goes way back. Unicode, of course, has some very specific and extensive, if not confusing, terminology and one should go there to get the story straight from the horse's mouth, but I was just chiming in to to note that "encoding" is short for "coded character set" and Unicdode is exactly that, at it's core.
Mar 17 2013
prev sibling next sibling parent "Paul D. Anderson" <paul.d.removethis.anderson comcast.andthis.net> writes:
On Friday, 1 March 2013 at 22:09:15 UTC, Ali Çehreli wrote:
 On 03/01/2013 01:51 PM, Paul D. Anderson wrote:

 In UTF-8 the "middle dot", ('•', \u00B7) and
 "multiplication sign", ('×', \u00D7)

[...]
 UTF-16 has many more mathematical symbols

Sorry to pick on this unrelated issue but UTF-8 and UTF-16 are just Unicode encodings. Unicode itself defines all of those characters and they can all be represented in any encoding. Ali

Yes, you are correct.
Mar 01 2013
prev sibling next sibling parent reply "Era Scarecrow" <rtcvb32 yahoo.com> writes:
On Friday, 1 March 2013 at 21:52:00 UTC, Paul D. Anderson wrote:
 Operator overloading in D is straightforward and sensible.

 I think there is an opportunity for D to do better with some 
 very small changes.

 I propose including additional Unicode mathematical symbols as 
 recognized operators for opBinary. All that would be required 
 is to extend the lexer to recognize the symbols as binary 
 operators.

 For example, in vector arithmetic there are two different 
 products defined -- the dot product and the cross product. Most 
 implementations I've seen overload '*' for the inner product, 
 but omit operator for the cross product. In UTF-8 the "middle 
 dot", ('•', \u00B7) and "multiplication sign", ('×', \u00D7), 
 correspond to the more usual mathematical notation for the dot 
 and cross products, respectively.

 UTF-16 has many more mathematical symbols, particularly on the 
 2200-22FF and 2A00-2AFF code pages. \u2207 is a wedge, commonly 
 used for outer products. The circled plus (u\2A01) and circled 
 times sign (\2A02) are defined for some mathematical 
 operations. \u2A33 is the "smash product" symbol, which I've 
 never heard of before but it sounds cool.

 Pros:
 1. Extends the capability to define mathematical operators for 
 user-defined types
 2. Shouldn't break any existing code since the symbols aren't 
 valid chars in identifiers (as far as I can tell) and aren't 
 being used elsewhere.
 3. Takes advantage of the existing opBinary overloading so 
 implementation should be straightforward.

 Cons:
 1. They are hard to type or otherwise enter in to a text file.
 2. They may not display correctly in some output forms.
 3. They could be confusing to someone unfamiliar with the 
 concept.

In windows (x86, could include dos & linux?) you can hold down the alt key and manually type in the value of the character; But it seems to truncated to 8 bits so Alt+321 = 65 which is A, so likely unless you're copy/pasting the symbols it probably won't work.
 With regard to the difficulty of entering or displaying these 
 characters, I think that is largely because modern computer 
 languages only give lip service to Unicode -- code is almost 
 exclusively written in ASCII. I have seen one instance where a 
 certain mathematical constant was named '?', but the author was 
 an iconoclast and pariah.

Those operators seem more useful for scientific math. I wouldn't want them added to to the core language though. ASCII can be typed with (almost) any keyboard and use any editor (new or old); You can still read source code if outputted to a dumb terminal rather than getting odd symbols (whitespace as well) and may be tearing your hair out wondering what this UTF-8 symbol is or what it means.
Mar 01 2013
next sibling parent FG <home fgda.pl> writes:
On 2013-03-01 23:56, Era Scarecrow wrote:
   Those operators seem more useful for scientific math. I wouldn't want them
 added to to the core language though.

   ASCII can be typed with (almost) any keyboard and use any editor (new or
old);
 You can still read source code if outputted to a dumb terminal rather than
 getting odd symbols (whitespace as well) and may be tearing your hair out
 wondering what this UTF-8 symbol is or what it means.

Gotta grab that old APL keyboard from the attic...
Mar 01 2013
prev sibling next sibling parent Artur Skawina <art.08.09 gmail.com> writes:
On 03/05/13 00:23, H. S. Teoh wrote:
 On Tue, Mar 05, 2013 at 12:17:06AM +0100, Marco Leise wrote:
 Am Mon, 04 Mar 2013 23:36:29 +0100
 schrieb "bearophile" <bearophileHUGS lycos.com>:

 jerro:

 Of course, expression templates should also be much easier
 to implement in D than they are in C++.

I don't remember seeing them implemented in D, so far. Bye, bearophile



They are trivial to implement, i even gave you an example in the past: http://forum.dlang.org/post/mailman.1195.1344699986.31962.digitalmars-d puremagic.com
 It's not as easy to do without C++'s convoluted constructor
 lookup rules. The clean approach of D makes it impossible to
 call a constructor implicitly like they do on the Wikipedia
 page about expression templates.
 But the approach with a small DSL looks ok, too. Not quite as
 seamless as the C++ version though.

The advantage of using DSLs is that you are free of syntax constraints

One problem with string-based DSLs is scoping - they only work properly when mixed in into the current scope. auto c = mixin(myDSL!"a?:+:b"); mixin myDSL!("c", "a?:+:b"); mixin (myDSL!("c", "a?:+:b")); // etc is sometimes enough, but often the code would be clearer w/o the mixin. artur
Mar 05 2013
prev sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Mar 05, 2013 at 01:40:19PM +0100, Artur Skawina wrote:
 On 03/05/13 00:23, H. S. Teoh wrote:
 On Tue, Mar 05, 2013 at 12:17:06AM +0100, Marco Leise wrote:
 Am Mon, 04 Mar 2013 23:36:29 +0100
 schrieb "bearophile" <bearophileHUGS lycos.com>:

 jerro:

 Of course, expression templates should also be much easier
 to implement in D than they are in C++.

I don't remember seeing them implemented in D, so far. Bye, bearophile



They are trivial to implement, i even gave you an example in the past: http://forum.dlang.org/post/mailman.1195.1344699986.31962.digitalmars-d puremagic.com

Very nice!! I like the way you use alias parameters to alleviate the need for C++-style expression-tree-simulation templates. Very clever! Yet another D feature that I haven't fully appreciated the full power of. T -- Nothing in the world is more distasteful to a man than to take the path that leads to himself. -- Herman Hesse
Mar 05 2013
prev sibling next sibling parent "Paul D. Anderson" <paul.d.removethis.anderson comcast.andthis.net> writes:
On Friday, 1 March 2013 at 22:56:27 UTC, Era Scarecrow wrote:
  Those operators seem more useful for scientific math. I 
 wouldn't want them added to to the core language though.

I agree that they are not going to be used by most programmers. This is true for a lot of Phobos, which is sensible because modules can be imported or not, as need be. My bottom line is the need to define at least one more product operator. I only propose adding it to the core language because I can't find a way to make it happen in a library. I am open to suggestions.
Mar 01 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
 Maybe #* #max #min? (Also usable with a "=" prefix, #=* #=max 
 #=min).

Sorry, I meant postfix: #*= #max= #min= So instead of: foo = min(foo, bar); foo = foo.min(bar); You write: foo #min= bar; (This syntax is generalizable to any diadic function. But I don't think D has to go there.) An alternative syntax: * max min *= max= min= Another alternative syntax for the second multiplication operator: auto M3 = M1 ^* M2; Having all future D scientific libraries use the same nice and clean standard operator has some advantages. Bye, bearophile
Mar 01 2013
prev sibling next sibling parent "Era Scarecrow" <rtcvb32 yahoo.com> writes:
On Friday, 1 March 2013 at 23:29:43 UTC, Paul D. Anderson wrote:
 My bottom line is the need to define at least one more product 
 operator. I only propose adding it to the core language because 
 I can't find a way to make it happen in a library. I am open to 
 suggestions.

I'd say a DSL for the scientific library would be best, likely as a mixin, then the text could be processed and use it's own rules and replace symbols with function calls? //can mix regular operations and utf extras a = scientificCalc!"(s * 4) × 4"(s); //possible call formats? mixin(scientificCalc("a = (s * 4) × 4"));
Mar 01 2013
prev sibling next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Sat, Mar 02, 2013 at 01:31:19AM +0100, Era Scarecrow wrote:
 On Friday, 1 March 2013 at 23:29:43 UTC, Paul D. Anderson wrote:
My bottom line is the need to define at least one more product
operator. I only propose adding it to the core language because I
can't find a way to make it happen in a library. I am open to
suggestions.

I'd say a DSL for the scientific library would be best, likely as a mixin, then the text could be processed and use it's own rules and replace symbols with function calls? //can mix regular operations and utf extras a = scientificCalc!"(s * 4) 4"(s); //possible call formats? mixin(scientificCalc("a = (s * 4) 4"));

+1. With D's compile-time capabilities, DSLs give you arbitrarily complex custom syntax at essentially zero runtime cost. You can even implement compile-time DSL optimizers that produce optimized code like no overloaded operator ever can. T -- Who told you to swim in Crocodile Lake without life insurance??
Mar 01 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
 auto M3 = M1 ^* M2;

Maybe better: auto M3 = M1 *^ M2; Bye, bearophile
Mar 01 2013
prev sibling next sibling parent "Paul D. Anderson" <nobody hotmail.com> writes:
On Saturday, 2 March 2013 at 00:31:20 UTC, Era Scarecrow wrote:
 On Friday, 1 March 2013 at 23:29:43 UTC, Paul D. Anderson wrote:
 My bottom line is the need to define at least one more product 
 operator. I only propose adding it to the core language 
 because I can't find a way to make it happen in a library. I 
 am open to suggestions.

I'd say a DSL for the scientific library would be best, likely as a mixin, then the text could be processed and use it's own rules and replace symbols with function calls? //can mix regular operations and utf extras a = scientificCalc!"(s * 4) × 4"(s); //possible call formats? mixin(scientificCalc("a = (s * 4) × 4"));

That's just what I need. Thanks.
Mar 01 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Paul D. Anderson:

 That's just what I need. Thanks.

Really? :-) Bye, bearophile
Mar 01 2013
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Saturday, 2 March 2013 at 00:38:36 UTC, bearophile wrote:
 auto M3 = M1 ^* M2;

Maybe better: auto M3 = M1 *^ M2; Bye, bearophile

Yeah that one seems useful. Other not that much.
Mar 02 2013
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--14dae93a17231f5d0304d706407d
Content-Type: text/plain; charset=UTF-8

GCC has min and max operators, and the syntax is very clever:
  min = a <? b;
  max = a >? b;
Ie, a shorthand of the ?: operator, in a similar way that C# has '??'
(another really nice shorthand).


On 2 March 2013 10:20, bearophile <bearophileHUGS lycos.com> wrote:

 Maybe #* #max #min? (Also usable with a "=" prefix, #=* #=max #=min).

Sorry, I meant postfix: #*= #max= #min= So instead of: foo = min(foo, bar); foo = foo.min(bar); You write: foo #min= bar; (This syntax is generalizable to any diadic function. But I don't think D has to go there.) An alternative syntax: * max min *= max= min= Another alternative syntax for the second multiplication operator: auto M3 = M1 ^* M2; Having all future D scientific libraries use the same nice and clean standard operator has some advantages. Bye, bearophile

--14dae93a17231f5d0304d706407d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">GCC has min and max operators, and the syntax is very clev= er:<div style>=C2=A0 min =3D a &lt;? b;</div><div style>=C2=A0 max =3D a &g= t;? b;</div><div style>Ie, a shorthand of the ?: operator, in a similar way= that C# has &#39;??&#39; (another really nice shorthand).</div> </div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On 2 Ma= rch 2013 10:20, bearophile <span dir=3D"ltr">&lt;<a href=3D"mailto:bearophi= leHUGS lycos.com" target=3D"_blank">bearophileHUGS lycos.com</a>&gt;</span>= wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><div class=3D"im"><blockquote class=3D"gmail= _quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:= 1ex"> Maybe #* #max #min? (Also usable with a &quot;=3D&quot; prefix, #=3D* #=3Dm= ax #=3Dmin).<br> </blockquote> <br></div> Sorry, I meant postfix:<br> <br> #*=3D #max=3D #min=3D<br> <br> So instead of:<br> <br> foo =3D min(foo, bar);<br> foo =3D foo.min(bar);<br> <br> You write:<br> <br> foo #min=3D bar;<br> <br> (This syntax is generalizable to any diadic function. But I don&#39;t think= D has to go there.)<br> <br> <br> An alternative syntax:<br> <br> * max min *=3D max=3D min=3D<br> <br> Another alternative syntax for the second multiplication operator:<br> <br> auto M3 =3D M1 ^* M2;<br> <br> Having all future D scientific libraries use the same nice and clean standa= rd operator has some advantages.<br> <br> Bye,<br> bearophile<br> </blockquote></div><br></div> --14dae93a17231f5d0304d706407d--
Mar 03 2013
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--14dae93b5e3667c49804d7065b87
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 2 March 2013 07:51, Paul D. Anderson <
paul.d.removethis.anderson comcast.andthis.net> wrote:

 1. They are hard to type or otherwise enter in to a text file.

I have =C3=97 and =C3=B7 on my keyboard; it's AltGr + '=3D'/'+', no center-= dot though :( I've always wanted those 2 operators! Sadly ascii just doesn't offer any sensible characters for it, and nobody seems to like unicode on code... --14dae93b5e3667c49804d7065b87 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">On 2 March 2013 07:51, Paul D. Anderson <span dir=3D"ltr">= &lt;<a href=3D"mailto:paul.d.removethis.anderson comcast.andthis.net" targe= t=3D"_blank">paul.d.removethis.anderson comcast.andthis.net</a>&gt;</span> = wrote:<br> <div class=3D"gmail_extra"><div class=3D"gmail_quote"><blockquote class=3D"= gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-= left:1ex">1. They are hard to type or otherwise enter in to a text file.<br=
</blockquote>

AltGr + &#39;=3D&#39;/&#39;+&#39;, no center-dot though :(</div><div style=
I&#39;ve always wanted those 2 operators! Sadly ascii just doesn&#39;t off=

...</div> </div></div></div> --14dae93b5e3667c49804d7065b87--
Mar 03 2013
prev sibling next sibling parent =?iso-8859-15?Q?Simen_Kj=E6r=E5s?= <simen.kjaras gmail.com> writes:
------------TUSL2TP2GcbyB9qiVyNfk9
Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes
Content-Transfer-Encoding: Quoted-Printable

On Sun, 03 Mar 2013 15:50:10 +0100, Manu <turkeyman gmail.com> wrote:

 On 2 March 2013 07:51, Paul D. Anderson  =

 <paul.d.removethis.anderson comcast.andthis.net> wrote:
 1. They are hard to type or otherwise enter in to a text file.

I have =D7 and =F7 on my keyboard; it's AltGr + '=3D'/'+', no center-d=

 though :(
 I've always wanted those 2 operators! Sadly ascii just doesn't offer a=

 sensible characters for it, and nobody seems to like unicode on code..=

I do. I so desperately want to be able to use those sensible operators f= or = mathy stuff. I *loved* seeing Fortress' list of operators, and it hurts= = not being able to use it. -- = Simen ------------TUSL2TP2GcbyB9qiVyNfk9 Content-Type: multipart/related; boundary=----------TUSL2TP2GcbyB9pSvIgI7Z ------------TUSL2TP2GcbyB9pSvIgI7Z Content-Type: text/html; charset=iso-8859-15 Content-ID: <op.1362338793020.e405a8655d6cd95c 192.168.43.33> Content-Transfer-Encoding: Quoted-Printable <!DOCTYPE html><html><head> <style type=3D"text/css">body { font-family:'Times New Roman'; font-size= :13px}</style> </head> <body>On Sun, 03 Mar 2013 15:50:10 +0100, Manu &lt;turkeyman gmail.com&g= t; wrote:<br><br><blockquote style=3D"margin: 0 0 0.80ex; border-left: #= 0000FF 2px solid; padding-left: 1ex"><div dir=3D"ltr">On 2 March 2013 07= :51, Paul D. Anderson <span dir=3D"ltr">&lt;<a href=3D"mailto:paul.d.rem= ovethis.anderson comcast.andthis.net" target=3D"_blank">paul.d.removethi= s.anderson comcast.andthis.net</a>&gt;</span> wrote:<br> <div class=3D"gmail_extra"><div class=3D"gmail_quote"><blockquote class=3D= "gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex">1. They are hard to type or otherwise enter in to a text f= ile.<br></blockquote> <div><br></div><div>I have =D7 and =F7 on my keyboard; it's AltGr + '=3D= '/'+', no center-dot though :(</div><div>I've always wanted those 2 oper= ators! Sadly ascii just doesn't offer any sensible characters for it, an= d nobody seems to like unicode on code...</div> </div></div></div> </blockquote><br>I do. I so desperately want to be able&nbsp;to use thos= e sensible operators for mathy stuff. &nbsp;I *loved* seeing Fortress' l= ist of operators, and it hurts not being able to use it.<br><br><div id=3D= "M2Signature"><div>-- </div><div>Simen</div></div></body></html> ------------TUSL2TP2GcbyB9pSvIgI7Z-- ------------TUSL2TP2GcbyB9qiVyNfk9--
Mar 03 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Andrei Alexandrescu:

 Gone. http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html

Do you know why? Those <? >? look nice enough, and maybe they are worth adding to D. But it's also useful to keep max and min as free functions because they are useful for higher-order functions (and because in D you can't give single operators to max and min): matrix1.map!max matrix2.map!max matrix3.map!length Bye, bearophile
Mar 03 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
 Those <? >? look nice enough, and maybe they are worth adding 
 to D.

But they are not essential. Maybe they were removed because they are too much non-standard. It's like "and" and "or": "and" and "or" are much better than "&&" and "||", but adding them to just one compiler, and keeping the older operators around, doesn't help make them popular at all. Bye, bearophile
Mar 03 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--20cf3074b90025d31804d70d4320
Content-Type: text/plain; charset=ISO-8859-1

On Mar 3, 2013 9:41 PM, "Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org>
wrote:
 On 3/3/13 9:42 AM, Manu wrote:
 GCC has min and max operators, and the syntax is very clever:
    min = a <? b;
    max = a >? b;
 Ie, a shorthand of the ?: operator, in a similar way that C# has '??'
 (another really nice shorthand).

Gone. http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html Andrei

And good riddance too. Regards -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --20cf3074b90025d31804d70d4320 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <p><br> On Mar 3, 2013 9:41 PM, &quot;Andrei Alexandrescu&quot; &lt;<a href=3D"mail= to:SeeWebsiteForEmail erdani.org">SeeWebsiteForEmail erdani.org</a>&gt; wro= te:<br> &gt;<br> &gt; On 3/3/13 9:42 AM, Manu wrote:<br> &gt;&gt;<br> &gt;&gt; GCC has min and max operators, and the syntax is very clever:<br> &gt;&gt; =A0 =A0min =3D a &lt;? b;<br> &gt;&gt; =A0 =A0max =3D a &gt;? b;<br> &gt;&gt; Ie, a shorthand of the ?: operator, in a similar way that C# has &= #39;??&#39;<br> &gt;&gt; (another really nice shorthand).<br> &gt;<br> &gt;<br> &gt; Gone. <a href=3D"http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features= .html">http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html</a><br> &gt;<br> &gt; Andrei<br> &gt;<br> &gt;</p> <p>And good riddance too. </p> <p>Regards<br> -- <br> Iain Buclaw</p> <p>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;;<br> </p> --20cf3074b90025d31804d70d4320--
Mar 03 2013
prev sibling next sibling parent "Peter Alexander" <peter.alexander.au gmail.com> writes:
On Sunday, 3 March 2013 at 22:58:02 UTC, bearophile wrote:
 Andrei Alexandrescu:

 Gone. 
 http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html

Do you know why?

Probably because they were non-standard, but don't look non-standard. It's not fun finding them in code that you want to compile with a different compiler...
Mar 03 2013
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--e89a8ff255d443a89704d70eb1b1
Content-Type: text/plain; charset=UTF-8

Nooooooo!
Why would they! ;)

Well I still think they're a great shorthand.


On 4 March 2013 07:38, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org>wrote:

 On 3/3/13 9:42 AM, Manu wrote:

 GCC has min and max operators, and the syntax is very clever:
    min = a <? b;
    max = a >? b;
 Ie, a shorthand of the ?: operator, in a similar way that C# has '??'
 (another really nice shorthand).

Gone. http://gcc.gnu.org/onlinedocs/**gcc/Deprecated-Features.html<http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html> Andrei

--e89a8ff255d443a89704d70eb1b1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Nooooooo!<div style>Why would they! ;)</div><div style><br=
</div><div style>Well I still think they&#39;re a great shorthand.</div></=

h 2013 07:38, Andrei Alexandrescu <span dir=3D"ltr">&lt;<a href=3D"mailto:S= eeWebsiteForEmail erdani.org" target=3D"_blank">SeeWebsiteForEmail erdani.o= rg</a>&gt;</span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><div class=3D"im">On 3/3/13 9:42 AM, Manu wr= ote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> GCC has min and max operators, and the syntax is very clever:<br> =C2=A0 =C2=A0min =3D a &lt;? b;<br> =C2=A0 =C2=A0max =3D a &gt;? b;<br> Ie, a shorthand of the ?: operator, in a similar way that C# has &#39;??&#3= 9;<br> (another really nice shorthand).<br> </blockquote> <br></div> Gone. <a href=3D"http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html= " target=3D"_blank">http://gcc.gnu.org/onlinedocs/<u></u>gcc/Deprecated-Fea= tures.html</a><span class=3D"HOEnZb"><font color=3D"#888888"><br> <br> Andrei<br> <br> <br> </font></span></blockquote></div><br></div> --e89a8ff255d443a89704d70eb1b1--
Mar 03 2013
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Sunday, 3 March 2013 at 21:38:44 UTC, Andrei Alexandrescu 
wrote:
 On 3/3/13 9:42 AM, Manu wrote:
 GCC has min and max operators, and the syntax is very clever:
   min = a <? b;
   max = a >? b;
 Ie, a shorthand of the ?: operator, in a similar way that C# 
 has '??'
 (another really nice shorthand).

Gone. http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html Andrei

I see nothing about the ?:, and it is indeed useful (or the ?? in C#, that has the same purpose).
Mar 04 2013
prev sibling next sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Fri, 1 Mar 2013 16:36:07 -0800
schrieb "H. S. Teoh" <hsteoh quickfur.ath.cx>:

 +1. With D's compile-time capabilities, DSLs give you arbitrarily
 complex custom syntax at essentially zero runtime cost. You can even
 implement compile-time DSL optimizers that produce optimized code like
 no overloaded operator ever can.
 
 
 T

Oh my fucking god. That means you can generate complex matrix-vector interactions "on the spot" without ever using temporary matrices or vectors and the inevitable cost of leaving the FPU and rounding to float! That's brilliant. -- Marco
Mar 04 2013
prev sibling next sibling parent "jerro" <a a.com> writes:
 Oh my fucking god. That means you can generate complex
 matrix-vector interactions "on the spot" without ever using
 temporary matrices or vectors and the inevitable cost of
 leaving the FPU and rounding to float! That's brilliant.

You can also do this using expression templates, and there are C++ libraries that do this. Of course, expression templates should also be much easier to implement in D than they are in C++.
Mar 04 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
jerro:

 Of course, expression templates should also be much easier
 to implement in D than they are in C++.

I don't remember seeing them implemented in D, so far. Bye, bearophile
Mar 04 2013
prev sibling next sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Mon, 04 Mar 2013 23:36:29 +0100
schrieb "bearophile" <bearophileHUGS lycos.com>:

 jerro:
 
 Of course, expression templates should also be much easier
 to implement in D than they are in C++.

I don't remember seeing them implemented in D, so far. Bye, bearophile

It's not as easy to do without C++'s convoluted constructor lookup rules. The clean approach of D makes it impossible to call a constructor implicitly like they do on the Wikipedia page about expression templates. But the approach with a small DSL looks ok, too. Not quite as seamless as the C++ version though. -- Marco
Mar 04 2013
prev sibling next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Mar 05, 2013 at 12:17:06AM +0100, Marco Leise wrote:
 Am Mon, 04 Mar 2013 23:36:29 +0100
 schrieb "bearophile" <bearophileHUGS lycos.com>:
 
 jerro:
 
 Of course, expression templates should also be much easier
 to implement in D than they are in C++.

I don't remember seeing them implemented in D, so far. Bye, bearophile

It's not as easy to do without C++'s convoluted constructor lookup rules. The clean approach of D makes it impossible to call a constructor implicitly like they do on the Wikipedia page about expression templates. But the approach with a small DSL looks ok, too. Not quite as seamless as the C++ version though.

The advantage of using DSLs is that you are free of syntax constraints in the hosting language. For example, you can add different symbols for dot product, cross product, transpose operator, etc., without being restricted by the operators that D allows you to overload. D's mixins allow you to transform such expressions into D code in non-trivial ways to achieve maximum performance in spite of the ease of writing it. T -- Shin: (n.) A device for finding furniture in the dark.
Mar 04 2013
prev sibling next sibling parent "Araq" <rumpf_a gmx.de> writes:
On Monday, 4 March 2013 at 21:58:34 UTC, Marco Leise wrote:
 Am Fri, 1 Mar 2013 16:36:07 -0800
 schrieb "H. S. Teoh" <hsteoh quickfur.ath.cx>:

 +1. With D's compile-time capabilities, DSLs give you 
 arbitrarily
 complex custom syntax at essentially zero runtime cost. You 
 can even
 implement compile-time DSL optimizers that produce optimized 
 code like
 no overloaded operator ever can.
 
 
 T

Oh my fucking god. That means you can generate complex matrix-vector interactions "on the spot" without ever using temporary matrices or vectors and the inevitable cost of leaving the FPU and rounding to float! That's brilliant.

It's slightly amusing you keep re-inventing Nimrod, albeit poorly: http://build.nimrod-code.org/docs/manual.html#term-rewriting-macros
Mar 04 2013
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Monday, 4 March 2013 at 23:17:33 UTC, Marco Leise wrote:
 Am Mon, 04 Mar 2013 23:36:29 +0100
 schrieb "bearophile" <bearophileHUGS lycos.com>:

 jerro:
 
 Of course, expression templates should also be much easier
 to implement in D than they are in C++.

I don't remember seeing them implemented in D, so far. Bye, bearophile

It's not as easy to do without C++'s convoluted constructor lookup rules. The clean approach of D makes it impossible to call a constructor implicitly like they do on the Wikipedia page about expression templates. But the approach with a small DSL looks ok, too. Not quite as seamless as the C++ version though.

You can use alias this to create implicit conversion.
Mar 04 2013
prev sibling next sibling parent "Don" <turnyourkidsintocash nospam.com> writes:
On Monday, 4 March 2013 at 23:29:09 UTC, Araq wrote:
 On Monday, 4 March 2013 at 21:58:34 UTC, Marco Leise wrote:
 Am Fri, 1 Mar 2013 16:36:07 -0800
 schrieb "H. S. Teoh" <hsteoh quickfur.ath.cx>:

 +1. With D's compile-time capabilities, DSLs give you 
 arbitrarily
 complex custom syntax at essentially zero runtime cost. You 
 can even
 implement compile-time DSL optimizers that produce optimized 
 code like
 no overloaded operator ever can.
 
 
 T

Oh my fucking god. That means you can generate complex matrix-vector interactions "on the spot" without ever using temporary matrices or vectors and the inevitable cost of leaving the FPU and rounding to float! That's brilliant.

It's slightly amusing you keep re-inventing Nimrod, albeit poorly: http://build.nimrod-code.org/docs/manual.html#term-rewriting-macros

My talk on this topic in the first D conference was in 2007. It seems Nimrod only dates from 2009. There's nothing new here.
Mar 05 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
jerro, Marco Leise, H. S. Teoh:

 Of course, expression templates should also be much easier
 to implement in D than they are in C++.

I don't remember seeing them implemented in D, so far. Bye, bearophile




Artur Skawina:
 They are trivial to implement, i even gave you an example in 
 the past:

 http://forum.dlang.org/post/mailman.1195.1344699986.31962.digitalmars-d puremagic.com

My memory is not perfect, and I don't remember that example. I will take a look, thank you. Bye, bearophile
Mar 05 2013
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Tuesday, 5 March 2013 at 13:17:52 UTC, bearophile wrote:
 jerro, Marco Leise, H. S. Teoh:

 Of course, expression templates should also be much easier
 to implement in D than they are in C++.

I don't remember seeing them implemented in D, so far. Bye, bearophile




Artur Skawina:
 They are trivial to implement, i even gave you an example in 
 the past:

 http://forum.dlang.org/post/mailman.1195.1344699986.31962.digitalmars-d puremagic.com

My memory is not perfect, and I don't remember that example. I will take a look, thank you. Bye, bearophile

SciD also uses them: http://forum.dlang.org/post/drwsjxtqxcdpwdbjojgq forum.dlang.org
Mar 05 2013
prev sibling parent "Era Scarecrow" <rtcvb32 yahoo.com> writes:
On Tuesday, 5 March 2013 at 12:40:32 UTC, Artur Skawina wrote:
 One problem with string-based DSLs is scoping - they only work 
 properly when mixed in into the current scope.

    auto c = mixin(myDSL!"a?:+:b");
    mixin myDSL!("c", "a?:+:b");
    mixin (myDSL!("c", "a?:+:b"));
    // etc

 is sometimes enough, but often the code would be clearer w/o 
 the mixin.

Perhaps the mixin ( mixin?) could be moved to a function's signature as an attribute? Then the compiler knows it's going to be mixed in and removes the need to do it yourself; Mind you it would have to return a string to be valid; Or it would be part of the base signature instead. string myDSL(string) mixin; mixin string myDSL(string); //now without the mixin.. auto c = myDSL!("a?:+:b"); This seems like it would be an easy thing to add and shouldn't complicate the language any.
Mar 05 2013