April 25, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On 4/25/2020 3:27 AM, Stefan Koch wrote:
> template Add3(alias y)
> {
> enum Add3 = y + 3;
> }
>
> enum x = staticMap!(Add3, big_seq).length;
Can also do:
enum x = staticMap!("a + 3", big_seq).length;
or:
enum x = staticMap!(y => y + 3, big_seq).length;
which looks a little nicer.
|
April 25, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On 4/25/2020 3:40 AM, Stefan Koch wrote:
> I just wanted to show off that the parser accepts this properly.
I suspect it would be best for the lexer to reject it.
|
April 26, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joseph Rushton Wakeling Attachments:
| On Sat, Apr 25, 2020 at 8:40 PM Joseph Rushton Wakeling via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
> On Saturday, 25 April 2020 at 10:27:38 UTC, Stefan Koch wrote:
> > mixin("enum x = (big_seq + 3)....length;");
>
> Aaargh :-\
>
> I'm not anti the `...` operator per se but seeing `....` in there (and yes, I understand what's happening!) is not very friendly to the reader.
>
It did occur to me to require parens in this case... just because :P
|
April 26, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Saturday, 25 April 2020 at 21:33:35 UTC, Walter Bright wrote:
> On 4/25/2020 3:27 AM, Stefan Koch wrote:
>> template Add3(alias y)
>> {
>> enum Add3 = y + 3;
>> }
>>
>> enum x = staticMap!(Add3, big_seq).length;
>
> Can also do:
>
> enum x = staticMap!("a + 3", big_seq).length;
>
> or:
>
> enum x = staticMap!(y => y + 3, big_seq).length;
>
> which looks a little nicer.
You most certainly can't right now.
|
April 26, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joseph Rushton Wakeling | On 4/25/2020 2:09 AM, Joseph Rushton Wakeling wrote:
> [...]
Thank you. This is good stuff!
|
April 26, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Loher | On 4/25/2020 3:08 AM, Johannes Loher wrote:
> [...]
Thank you!
|
April 26, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On 4/24/2020 6:31 PM, Manu wrote: > On Sat, Apr 25, 2020 at 7:00 AM Walter Bright via Digitalmars-d <digitalmars-d@puremagic.com <mailto:digitalmars-d@puremagic.com>> wrote: > > > Let's not fall into the mode of only looking at the way C++ did it and not > seeing other ways. C++ has problems (like not having arrays) that lead it in > different directions for solving array-like problems. > > > It is so predictable that you will eventually produce a sentence like this whenever I suggest anything. I could have phrased that better. > I can't imagine a reason to change my proposal. The only reason I would consider changing it is if you can make your (like-arrays) proposal work... but it doesn't. I explored that a lot, believe it or not. I really wanted to believe it could work. I want to make sure it won't work, too, before abandoning it. I can understand finding that frustrating :-) > What do other languages do? How are things like this expressed in mathematics? > > C++ uses `...`, and they are the only language that has anything remotely like this. > Javascript also uses `...` for something similar-ish, so the web guys should find it familiar too. I don't remember Javascript doing that, though it's been 20 years since I worked on the JS compiler. Maybe it's a later addition. |
April 26, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Sunday, 26 April 2020 at 10:20:49 UTC, Walter Bright wrote:
> On 4/24/2020 6:31 PM, Manu wrote:
>> C++ uses `...`, and they are the only language that has anything remotely like this.
>> Javascript also uses `...` for something similar-ish, so the web guys should find it familiar too.
>
> I don't remember Javascript doing that, though it's been 20 years since I worked on the JS compiler. Maybe it's a later addition.
It is a recent addition, ES6 I believe.
They use it in destructuring:
```
const {a, b, rest...} = {a:1, b:2, c:3, d:4}; // rest == {c:3, d:4}
```
and in expanding arrays
```
function foo(a,b) {}
const ab = [1,2];
foo(...ab);
```
or objects
```
const ab = {a: 1, b: 2};
const cd = {...ab, c:3, d:4}; // cd == {a:1, b:2, c:3, d:4}
```
```
|
April 26, 2020 Re: I dun a DIP, possibly the best DIP ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sebastiaan Koppe | On Sunday, 26 April 2020 at 11:13:25 UTC, Sebastiaan Koppe wrote:
> On Sunday, 26 April 2020 at 10:20:49 UTC, Walter Bright wrote:
>> On 4/24/2020 6:31 PM, Manu wrote:
>>> Javascript also uses `...` for something similar-ish, so the web guys should find it familiar too.
>>
>> I don't remember Javascript doing that, though it's been 20 years since I worked on the JS compiler. Maybe it's a later addition.
>
> It is a recent addition, ES6 I believe.
>
> They use it in destructuring:
>
> ```
> const {a, b, rest...} = {a:1, b:2, c:3, d:4}; // rest == {c:3, d:4}
> ```
>
> and in expanding arrays
>
> ```
> function foo(a,b) {}
> const ab = [1,2];
> foo(...ab);
> ```
> snip
JavaScript uses ... as the spread operator. It expands an expression in places where multiple arguments are expected. Since JavaScript does not have tuples, arrays are used instead.
D's equivalent for JS ... operator on function parameters would be Tuple.expand
|
April 26, 2020 Re: Challenge: Motivating examples for ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On 4/25/20 2:52 PM, Paul Backus wrote:
> On Saturday, 25 April 2020 at 15:17:35 UTC, Steven Schveighoffer wrote:
>> I propose a function any which takes a range and returns true if any element matches the provided one. And another one all(val) which does the same if all are the value. This gives us maximum flexibility.
>
> Looks like std.algorithm.any and std.algorithm.all can already do this.
Nice! The only thing I would say is I don't want to have a giant nest of subcalls for something like this, which can be done with one foreach loop. I'll have to look at the implementation.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation