Thread overview | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 10, 2012 Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { } |
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | On Thursday, 10 May 2012 at 00:16:52 UTC, Mehrdad wrote:
> Is this possible/should it compile?
>
> If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me...
>
> void process(R)(R items, size_t maxCount = items.length)
> {
> }
Have you tried it?
I bet this isn't possible currently, but do open an enhancement request if it isn't. It's going to be a bit tricky to implement, but I like it.
|
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matt Peterson | On Thursday, 10 May 2012 at 01:06:31 UTC, Matt Peterson wrote:
> On Thursday, 10 May 2012 at 00:16:52 UTC, Mehrdad wrote:
>> Is this possible/should it compile?
>>
>> If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me...
>>
>> void process(R)(R items, size_t maxCount = items.length)
>> {
>> }
>
> Have you tried it?
>
> I bet this isn't possible currently, but do open an enhancement request if it isn't. It's going to be a bit tricky to implement, but I like it.
Well I mean of course I tried it (and it didn't work), but I was just making sure I wasn't doing something wrong and that it wasn't recently added or something.
Ok I'll make a request for it.
|
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | http://d.puremagic.com/issues/show_bug.cgi?id=8075 |
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | On Wed, 09 May 2012 20:16:51 -0400, Mehrdad <wfunction@hotmail.com> wrote: > Is this possible/should it compile? > > If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... > > void process(R)(R items, size_t maxCount = items.length) > { > } I *love* this idea. Although, what happens if the expression for items is costly? We have to make sure if you do: process(someExpensiveCalculation()); it doesn't turn into: process(someExpensiveCalculation(), someExpensiveCalculation().length); -Steve |
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thursday, 10 May 2012 at 11:54:42 UTC, Steven Schveighoffer wrote: > I *love* this idea. :D > Although, what happens if the expression for items is costly? We have to make sure if you do: > > process(someExpensiveCalculation()); > > it doesn't turn into: > > process(someExpensiveCalculation(), someExpensiveCalculation().length); It should be evaluated once anyway, since it might have side effects. |
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | Am 10.05.2012 02:16, schrieb Mehrdad:
> Is this possible/should it compile?
>
> If not, should I make an enhancement request for it? It's been something
> that would've been useful in a ton of situations for me...
>
> void process(R)(R items, size_t maxCount = items.length)
> {
> }
Solution:
void process(R)(R items) {
process(items, items.length);
}
void process(R)(R items, int maxCount);
Is such a miminal syntactic sugar addition worth it?
|
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mafi | On Thursday, 10 May 2012 at 14:11:32 UTC, Mafi wrote:
> Am 10.05.2012 02:16, schrieb Mehrdad:
>> Is this possible/should it compile?
>>
>> If not, should I make an enhancement request for it? It's been something
>> that would've been useful in a ton of situations for me...
>>
>> void process(R)(R items, size_t maxCount = items.length)
>> {
>> }
>
> Solution:
> void process(R)(R items) {
> process(items, items.length);
> }
>
> void process(R)(R items, int maxCount);
>
> Is such a miminal syntactic sugar addition worth it?
Yes! That's, like, 80 fewer characters... And it doesn't scale with multiple optional arguments..
|
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | On Thursday, 10 May 2012 at 14:33:32 UTC, Mehrdad wrote:
> On Thursday, 10 May 2012 at 14:11:32 UTC, Mafi wrote:
>> Am 10.05.2012 02:16, schrieb Mehrdad:
>>> Is this possible/should it compile?
>>>
>>> If not, should I make an enhancement request for it? It's been something
>>> that would've been useful in a ton of situations for me...
>>>
>>>
> Yes! That's, like, 80 fewer characters... And it doesn't scale with multiple optional arguments..
er, more* characters
|
May 10, 2012 Re: Optional parameters referring to previous parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | On Thursday, 10 May 2012 at 14:33:32 UTC, Mehrdad wrote:
> On Thursday, 10 May 2012 at 14:11:32 UTC, Mafi wrote:
>> Am 10.05.2012 02:16, schrieb Mehrdad:
>>> Is this possible/should it compile?
>>>
>>> If not, should I make an enhancement request for it? It's been something
>>> that would've been useful in a ton of situations for me...
>>>
>>>
> Yes! That's, like, 80 fewer characters... And it doesn't scale with multiple optional arguments..
er, more* characters
|
Copyright © 1999-2021 by the D Language Foundation