January 13, 2012
"Nick Sabalausky" <a@a.a> skrev i meddelandet news:jeq6h1$18mu$1@digitalmars.com...
> "Manu" <turkeyman@gmail.com> wrote in message news:mailman.328.1326483521.16222.digitalmars-d@puremagic.com... On 13 January 2012 21:24, Grue <Grue@nop.com> wrote:
>>>
>>> Beware... your statement has awoken an "Ancient Forum Lurker"! ;)
>>>
>>
>>Sweet! I have that effect :P
>
> Arise!
>

Haha, just as I was beginning to suspect the predictions of 2012 were true... but whew, language crisis narrowly averted! ;) Now I can go back to planning my wedding instead... :P

Manu" <turkeyman@gmail.com> wrote in message
> Perhaps D could support the unicode characters '²' '³' or 'ª' as kinda handy operators.

You know... that's an interesting idea... but there's a far cooler possibility lurking around the corner... Remember the first time you experienced 'syntax highlighting' and how limiting it felt to go back to a black&white afterwards?

Imagine... an IDE/editor with pretty formatting of math source expressions... even if it was just limited to... fractions and maybe sqrt... byebye ubiquitous parentheses hell... say hi to readable expressions!

Proper fractions would be a killer feature for readability... and there would be no language change needed at all... Am I the only one upset with the obvious omissions of must have math symbols from normal keyboards... sqrt, pretty please?!


January 13, 2012
On 13/01/2012 19:24, Grue wrote:
<snip>
> Beware... your statement has awoken an "Ancient Forum Lurker"! ;)
> 1. Google -5^2, result: -(5^2) = -25
> 2. Start ancient TI graphing calculator(which by the way has a special unary (-) minus
> operator).
> -5^2 = -25
> -5*²* = -25
<snip>

And probably most BASICs.  Just checked VBA and Spectrum BASIC.  Once upon a time I would have had QBasic to test on as well.

Stewart.
January 13, 2012
My HP 49g+ does -2^2 = -4 as well (with special unary minus), in algebraic mode. Would love to test it on the 41C, but it only has RPN. ^_^

I've been swayed into the »let's keep it« direction.

I'll start using it, too. It even works as an array operator. =D

On 14 January 2012 00:30, Stewart Gordon <smjg_1998@yahoo.com> wrote:
> On 13/01/2012 19:24, Grue wrote:
> <snip>
>>
>> Beware... your statement has awoken an "Ancient Forum Lurker"! ;)
>> 1. Google -5^2, result: -(5^2) = -25
>> 2. Start ancient TI graphing calculator(which by the way has a special
>> unary (-) minus
>> operator).
>> -5^2 = -25
>> -5*²* = -25
>
> <snip>
>
> And probably most BASICs.  Just checked VBA and Spectrum BASIC.  Once upon a time I would have had QBasic to test on as well.
>
> Stewart.
January 14, 2012
On 1/13/2012 11:25 AM, Manu wrote:
> Fair call. I buy this argument. If there is a precedent set by (multiple) other
> languages towards this precedence (and none against), then so be it.
> If there were a vote though, I'd vote for it being deprecated on grounds of
> offering nothing to the language more than confusion.

I suspect that pow may be better off as a compiler intrinsic.
January 14, 2012
On 01/13/2012 07:48 AM, bearophile wrote:
> This is the third time I see people trip on power operator precedence:
> http://d.puremagic.com/issues/show_bug.cgi?id=7268
>
> Some people expect this:
> (-10 ^^ 2)
> To be 100 instead of -100
> (Note: Python here uses the same operator precedences.)
>
> Do you think it's worth (and possible) to help D programmers avoid this mistake in their code?
>
> Bye,
> bearophile

I read some of the other responses and... ewwwww.

My only conclusion is that there is no right answer in the precedence dichotomy, so my suggestion is to ditch the dichotomy.

Off hand, I'd be comfortable with forbidding such ambiguous expressions (in human readability terms; I know the grammar is fine).  It'd be in the spirit of things like "if (a = b)".  Parentheses would be required, so one must write
(-10)^^2
or
-(10^^2)

I imagine this would make sense for all unary operators colliding with ^^:

++10^^2    // wtf does this do?
...
(++10)^^2  // aha!
or
++(10^^2)  // aha!

January 14, 2012
Chad J:

> Parentheses would be required, so one must write
> (-10)^^2
> or
> -(10^^2)
> 
> I imagine this would make sense for all unary operators colliding with ^^:

Is this wise and good? What are Walter & Andrei & Don thinking about this?

Bye,
bearophile
January 14, 2012
On 1/13/2012 5:39 PM, Walter Bright wrote:
> On 1/13/2012 11:25 AM, Manu wrote:
>> Fair call. I buy this argument. If there is a precedent set by (multiple) other
>> languages towards this precedence (and none against), then so be it.
>> If there were a vote though, I'd vote for it being deprecated on grounds of
>> offering nothing to the language more than confusion.
>
> I suspect that pow may be better off as a compiler intrinsic.
I posted this once but it seemed to go ignored, so I'll post again ;)

I think a WARNING is the best route.
Kind of like when VC++ cries in pain when you say something like "a << b + c": http://msdn.microsoft.com/en-us/library/5d2e57c5.aspx
January 14, 2012
El 13/01/2012 21:29, bearophile escribió:
> Bioinformatics, exploratory programing, simulations, data munging, hardening of slow scripts, data visualization, data mining, optimization of some tasks, faster routines for dynamic code written by other people, and more.
>
> The problem is that often you don't have a "x", but a "long_named_variable", ...
> ...
>> Realistically, how often do you cube? It's extremely rare in my experience.
>
> ^^3 is not common.


I completely agree. The ^^ operator is a great addition in D even if it is not used very often. I always found awkward the lack of such operator in C-derived languages (some others use either ^ or **). And I was happy to see in the DMD source how ^^2 and ^^3 are rewritten to avoid pow().

There are indeed applications that use exponentiation and whose expressions using ^^ are much more readable and closer to the mathematical notation.

e.g. sphere_volume = 4./3 * PI * radius^^3; // so much better


As for the original discussion on precedence I think the first example is different to the others posted in that it uses a *number literal*.

in -x^^2, following standard math, it should be -(x^^2) (<0)

but the first example, -10^^2 is confusing because one might quickly see the - sign as part of the number literal. As long as in D the - sign is not part of the literal, the current behavior is fine. If you want it the other way around write:

(-10)^^2

January 14, 2012
On 01/14/2012 02:56 PM, Mehrdad wrote:
> On 1/13/2012 5:39 PM, Walter Bright wrote:
>> On 1/13/2012 11:25 AM, Manu wrote:
>>> Fair call. I buy this argument. If there is a precedent set by
>>> (multiple) other
>>> languages towards this precedence (and none against), then so be it.
>>> If there were a vote though, I'd vote for it being deprecated on
>>> grounds of
>>> offering nothing to the language more than confusion.
>>
>> I suspect that pow may be better off as a compiler intrinsic.
> I posted this once but it seemed to go ignored, so I'll post again ;)
>
> I think a WARNING is the best route.
> Kind of like when VC++ cries in pain when you say something like "a << b
> + c": http://msdn.microsoft.com/en-us/library/5d2e57c5.aspx

Eh, unless things have changed in the past few years, D isn't really into warnings.  I'm fine with it being an error though.
1 2 3 4
Next ›   Last »