Jump to page: 1 214  
Page
Thread overview
Project Elvis
Oct 28, 2017
bauss
Oct 28, 2017
Daniel Kozak
Oct 29, 2017
bauss
Oct 30, 2017
w0rp
Oct 30, 2017
Satoshi
Oct 29, 2017
Jonathan M Davis
Oct 29, 2017
Jonathan M Davis
Oct 29, 2017
Jonathan M Davis
Oct 29, 2017
Nemanja Boric
Oct 29, 2017
Jonathan M Davis
Oct 29, 2017
Nemanja Boric
Oct 30, 2017
Jonathan M Davis
Oct 30, 2017
Jonathan M Davis
Oct 30, 2017
crimaniak
Oct 30, 2017
H. S. Teoh
Oct 30, 2017
Dejan Lekic
Nov 05, 2017
MrSmith
Oct 31, 2017
Mark
Oct 31, 2017
bauss
Nov 01, 2017
Mark
Nov 02, 2017
Nick Treleaven
Nov 02, 2017
H. S. Teoh
Nov 02, 2017
Jonathan M Davis
Nov 06, 2017
Neia Neutuladh
Nov 06, 2017
bauss
Nov 06, 2017
Jonathan M Davis
Nov 06, 2017
Satoshi
Nov 06, 2017
Jonathan M Davis
Nov 06, 2017
Biotronic
Nov 10, 2017
Nathan S.
Nov 13, 2017
Nick Treleaven
Nov 08, 2017
aberba
Nov 08, 2017
codephantom
Nov 08, 2017
jmh530
Nov 06, 2017
Adam Wilson
Nov 06, 2017
Dmitry Olshansky
Nov 06, 2017
Jacob Carlborg
Nov 06, 2017
Meta
Nov 07, 2017
user1234
Nov 08, 2017
Meta
Nov 13, 2017
Nick Treleaven
Nov 06, 2017
Michael
Nov 10, 2017
Adam Wilson
Nov 10, 2017
codephantom
Nov 10, 2017
Adam Wilson
Nov 10, 2017
codephantom
Nov 10, 2017
Jonathan M Davis
Nov 10, 2017
codephantom
Nov 10, 2017
codephantom
Nov 10, 2017
codephantom
Nov 10, 2017
Satoshi
Nov 10, 2017
codephantom
Nov 10, 2017
Satoshi
Nov 10, 2017
codephantom
Nov 10, 2017
codephantom
Nov 10, 2017
Satoshi
Nov 10, 2017
codephantom
Nov 10, 2017
codephantom
Nov 11, 2017
12345swordy
Nov 11, 2017
codephantom
Nov 11, 2017
12345swordy
Nov 11, 2017
codephantom
Nov 11, 2017
12345swordy
Nov 12, 2017
codephantom
Nov 11, 2017
codephantom
Nov 11, 2017
codephantom
Nov 11, 2017
Patrick Schluter
Nov 11, 2017
codephantom
Nov 11, 2017
rikki cattermole
Nov 11, 2017
Satoshi
Nov 12, 2017
codephantom
Nov 12, 2017
codephantom
Nov 12, 2017
codephantom
Nov 12, 2017
Satoshi
Nov 11, 2017
Andre Pany
Nov 12, 2017
bauss
Nov 12, 2017
codephantom
Nov 12, 2017
codephantom
Nov 12, 2017
codephantom
Nov 12, 2017
codephantom
Nov 12, 2017
codephantom
Nov 12, 2017
Satoshi
Nov 12, 2017
Satoshi
Nov 12, 2017
Satoshi
Nov 12, 2017
codephantom
Nov 12, 2017
bauss
Nov 13, 2017
codephantom
Nov 13, 2017
codephantom
Nov 10, 2017
codephantom
Nov 10, 2017
Jonathan M Davis
Nov 10, 2017
codephantom
Nov 10, 2017
Satoshi
Nov 10, 2017
codephantom
Nov 10, 2017
codephantom
Nov 10, 2017
bauss
Nov 10, 2017
codephantom
Nov 10, 2017
codephantom
Nov 10, 2017
codephantom
Nov 10, 2017
codephantom
Nov 10, 2017
Satoshi
Nov 10, 2017
Michael
Nov 10, 2017
meppl
Nov 10, 2017
Patrick Schluter
Nov 10, 2017
codephantom
Nov 11, 2017
codephantom
Nov 11, 2017
codephantom
Nov 13, 2017
Nick Treleaven
Nov 07, 2017
Satoshi
Nov 07, 2017
Dejan Lekic
Nov 07, 2017
Atila Neves
Nov 07, 2017
bauss
Nov 07, 2017
jmh530
Nov 07, 2017
bauss
Nov 07, 2017
bauss
October 28, 2017
Walter and I decided to kick-off project Elvis for adding the homonym operator to D.

Razvan Nitu has already done a good part of the work:

https://github.com/dlang/dmd/pull/7242
https://github.com/dlang/dlang.org/pull/1917
https://github.com/dlang/dlang.org/pull/1918

What's needed is a precise DIP that motivates the feature properly and provides a good proposal for it. I'm no fan of bureaucracy but we really need to be pedantic about introducing language features. Walter argued thusly in a PR, and I agree:

"I'm concerned that the elvis operator is not well understood, and we shouldn't be designing it in the comments section here. A DIP needs to be written. Things like operator precedence, side effects, type resolution, comparison with the operator in other languages, grammar changes, lvalues, how it would appear in the generated .di file if it isn't its own operator, etc., should be addressed."

A lowering looks like the straightforward approach, of the kind:

expr1 ?: expr2

==>

(x => x ? x : expr2)(expr1)

Who wants to join Razvan in Project Elvis?


Thanks,

Andrei
October 28, 2017
On Saturday, 28 October 2017 at 11:38:52 UTC, Andrei Alexandrescu wrote:
> Walter and I decided to kick-off project Elvis for adding the homonym operator to D.
>
> [...]

This is honestly going to be a great addition.
October 28, 2017
Wait? You are saying D does not support this yet? Wow :D. I have been using this so often in work (PHP) so I can beleive I have not miss this

On Sat, Oct 28, 2017 at 2:39 PM, bauss via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> On Saturday, 28 October 2017 at 11:38:52 UTC, Andrei Alexandrescu wrote:
>
>> Walter and I decided to kick-off project Elvis for adding the homonym operator to D.
>>
>> [...]
>>
>
> This is honestly going to be a great addition.
>


October 29, 2017
On Saturday, 28 October 2017 at 11:38:52 UTC, Andrei Alexandrescu wrote:
> expr1 ?: expr2

So, what will the member function be called? «opElvis»? No…

October 29, 2017
On Sunday, 29 October 2017 at 10:08:41 UTC, Ola Fosheim Grøstad wrote:
> On Saturday, 28 October 2017 at 11:38:52 UTC, Andrei Alexandrescu wrote:
>> expr1 ?: expr2
>
> So, what will the member function be called? «opElvis»? No…

opCast for bool.

-Steve
October 29, 2017
On Sunday, 29 October 2017 at 11:23:19 UTC, Steven Schveighoffer wrote:
>> So, what will the member function be called? «opElvis»? No…
>
> opCast for bool.

That means you cannot create your own type-safe filtering mechanism, but will be forced to provide opCast for bool.

October 29, 2017
On Sunday, 29 October 2017 at 14:27:34 UTC, Ola Fosheim Grøstad wrote:
> On Sunday, 29 October 2017 at 11:23:19 UTC, Steven Schveighoffer wrote:
>>> So, what will the member function be called? «opElvis»? No…
>>
>> opCast for bool.
>
> That means you cannot create your own type-safe filtering mechanism, but will be forced to provide opCast for bool.

That breaks down if you want do filter out invalid values where zero is a valid value. For instance if you have an integer type that tracks overflow:

calc(maybe_overflow_integer :? 0)

So casting to bool is a poor choice for the typical use context.

October 29, 2017
On Sunday, October 29, 2017 14:27:34 Ola Fosheim Grøstad via Digitalmars-d wrote:
> On Sunday, 29 October 2017 at 11:23:19 UTC, Steven Schveighoffer
>
> wrote:
> >> So, what will the member function be called? «opElvis»? No…
> >
> > opCast for bool.
>
> That means you cannot create your own type-safe filtering mechanism, but will be forced to provide opCast for bool.

opCast with bool is precisely how you already provide overloads for dealing with every other place in the language that a boolean condition is used - the ternary operator, assertions, if statements, while loops, and for loops (which I think is everything, but I could have missed something). As proposed thus far, the Elvis operator is just the ternary operator where the condition is reused as the first branch, so having it work with opCast fits in perfectly with everything else.

What would you be looking to do that does not fit in with this?

- Jonathan M Davis


October 29, 2017
On 10/29/17 10:35 AM, Ola Fosheim Grøstad wrote:
> On Sunday, 29 October 2017 at 14:27:34 UTC, Ola Fosheim Grøstad wrote:
>> On Sunday, 29 October 2017 at 11:23:19 UTC, Steven Schveighoffer wrote:
>>>> So, what will the member function be called? «opElvis»? No…
>>>
>>> opCast for bool.
>>
>> That means you cannot create your own type-safe filtering mechanism, but will be forced to provide opCast for bool.
> 
> That breaks down if you want do filter out invalid values where zero is a valid value. For instance if you have an integer type that tracks overflow:
> 
> calc(maybe_overflow_integer :? 0)
> 
> So casting to bool is a poor choice for the typical use context.

I would have expected Nullable!int to fit the bill, but unfortunately, opCast(bool) doesn't work on a null Nullable.

But certainly you can construct a type that does work.

-Steve
October 29, 2017
On Sunday, 29 October 2017 at 14:37:57 UTC, Jonathan M Davis wrote:
> everything, but I could have missed something). As proposed thus far, the Elvis operator is just the ternary operator where the condition is reused as the first branch, so having it work with opCast fits in perfectly with everything else.

I understand that it is being defined as a short hand for the ordinary ternary operator, but if you look at the use context the elvis-operator tend to be used to filter out invalid state.

So if casting to bool would test for validity then it would make more sense, but that is not the general case...

> What would you be looking to do that does not fit in with this?

I think it would be better to have a test for validity and use that for substituting in default values (which is what the elvis operator is typically used for).

« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11