Date: Thu, 23 Nov 2023 23:31:15 -0500
I don't see a lot of motivation for this feature, but if we were to
pursue a notation for this, a bracket notation would allow more
expressiveness and would be more inline with common mathematical notation.
int a = ...;
int b = ...;
int c = |b-a|;
Unfortunately, '|' (U+007C VERTICAL LINE) isn't available to be
repurposed like this. There are a couple of other options.
' ∣' (U+2223 DIVIDES) is available, but it isn't intended for use as an
absolute value symbol and its similarity to U+007C makes use of it a
questionable choice.
'‖' (U+2016 DOUBLE VERTICAL LINE) is available, but that character is
generally used to express a mathematical norm and that is not the same
as the absolute value.
None of these options provides distinct characters for left vs right
ends of the notation, so would require parenthesis when nested.
Other Unicode characters could of course be employed for a new syntax,
but meh, abs() already exists and if we were going to add more operators
to the language, this wouldn't be my first choice.
Tom.
On 11/23/23 5:43 PM, Rik van der Brugghen via Std-Proposals wrote:
> Hi.
>
> Maybe suggested before, but would be great with
>
> a = |b; // a = abs (b)
>
> That's it, exactly same semantic behaviour (precedence and all that
> stuff) as ~b.
>
> Best regards,
> Rik van der Brugghen
> Stockholm
>
>
pursue a notation for this, a bracket notation would allow more
expressiveness and would be more inline with common mathematical notation.
int a = ...;
int b = ...;
int c = |b-a|;
Unfortunately, '|' (U+007C VERTICAL LINE) isn't available to be
repurposed like this. There are a couple of other options.
' ∣' (U+2223 DIVIDES) is available, but it isn't intended for use as an
absolute value symbol and its similarity to U+007C makes use of it a
questionable choice.
'‖' (U+2016 DOUBLE VERTICAL LINE) is available, but that character is
generally used to express a mathematical norm and that is not the same
as the absolute value.
None of these options provides distinct characters for left vs right
ends of the notation, so would require parenthesis when nested.
Other Unicode characters could of course be employed for a new syntax,
but meh, abs() already exists and if we were going to add more operators
to the language, this wouldn't be my first choice.
Tom.
On 11/23/23 5:43 PM, Rik van der Brugghen via Std-Proposals wrote:
> Hi.
>
> Maybe suggested before, but would be great with
>
> a = |b; // a = abs (b)
>
> That's it, exactly same semantic behaviour (precedence and all that
> stuff) as ~b.
>
> Best regards,
> Rik van der Brugghen
> Stockholm
>
>
Received on 2023-11-24 04:31:17