Jump to page: 1 24  
Page
Thread overview
The amazing template which does nothing
Apr 28, 2015
Vladimir Panteleev
Apr 28, 2015
Vladimir Panteleev
Apr 28, 2015
Chris
Apr 28, 2015
Andrea Fontana
Apr 28, 2015
John Colvin
Apr 28, 2015
John Colvin
Apr 28, 2015
Andrea Fontana
Apr 28, 2015
John Colvin
Apr 28, 2015
Vladimir Panteleev
Apr 29, 2015
John Colvin
Apr 29, 2015
Iain Buclaw
Apr 29, 2015
John Colvin
Apr 29, 2015
Iain Buclaw
Apr 29, 2015
Vladimir Panteleev
Apr 29, 2015
Iain Buclaw
Apr 29, 2015
John Colvin
Apr 29, 2015
Iain Buclaw
Apr 30, 2015
John Colvin
Apr 30, 2015
Iain Buclaw
Apr 28, 2015
Andrea Fontana
Apr 28, 2015
Dicebot
Apr 28, 2015
Vladimir Panteleev
Apr 28, 2015
Vladimir Panteleev
Apr 29, 2015
Chris
Spelling and phonetics (Was: The amazing template which does nothing)
Apr 29, 2015
Vladimir Panteleev
Apr 29, 2015
Chris
Apr 29, 2015
Marc Schütz
Apr 29, 2015
Chris
Apr 28, 2015
Max Samukha
Apr 28, 2015
Dicebot
Apr 29, 2015
Nikolay
Apr 29, 2015
Vladimir Panteleev
April 28, 2015
http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/
April 28, 2015
On 4/27/15 7:36 PM, Vladimir Panteleev wrote:
> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/

s/which/that/

Simple rule of thumb: if there's no comma before "which", consider replacing with "that". -- Andrei

April 28, 2015
On Tuesday, 28 April 2015 at 06:10:28 UTC, Andrei Alexandrescu wrote:
> On 4/27/15 7:36 PM, Vladimir Panteleev wrote:
>> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/
>
> s/which/that/
>
> Simple rule of thumb: if there's no comma before "which", consider replacing with "that". -- Andrei

Fixed, thanks.
April 28, 2015
On Tuesday, 28 April 2015 at 02:36:38 UTC, Vladimir Panteleev wrote:
> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/

Thanks for this little piece of information! Great stuff. You wrote

"When building an UFCS chain (in the style of component programming), you will often run into situations where a certain operation is not UFCS-able. There are multiple obvious ways to prepend the string, but neither are very satisfactory"

And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
April 28, 2015
On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.

A very slow (i guess) workaround could be:

"test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;

vs the new one:

"test".toUpper.Identity!(a => "This is a " ~ a).writeln;

April 28, 2015
On Tuesday, 28 April 2015 at 10:07:43 UTC, Andrea Fontana wrote:
> On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
>> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
>
> A very slow (i guess) workaround could be:
>
> "test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
>
> vs the new one:
>
> "test".toUpper.Identity!(a => "This is a " ~ a).writeln;

Shouldn't be slow, your just giving the optimiser some work to do*, but you're always better off with the second one.

*Assuming a good optimiser. dmd won't work this out.
April 28, 2015
On Tuesday, 28 April 2015 at 10:18:12 UTC, John Colvin wrote:
> On Tuesday, 28 April 2015 at 10:07:43 UTC, Andrea Fontana wrote:
>> On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
>>> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
>>
>> A very slow (i guess) workaround could be:
>>
>> "test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
>>
>> vs the new one:
>>
>> "test".toUpper.Identity!(a => "This is a " ~ a).writeln;
>
> Shouldn't be slow, your just giving the optimiser some work to do*, but you're always better off with the second one.
>
> *Assuming a good optimiser. dmd won't work this out.

s/your/you're
April 28, 2015
On Tuesday, 28 April 2015 at 10:18:49 UTC, John Colvin wrote:
> On Tuesday, 28 April 2015 at 10:18:12 UTC, John Colvin wrote:
>> On Tuesday, 28 April 2015 at 10:07:43 UTC, Andrea Fontana wrote:
>>> On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
>>>> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
>>>
>>> A very slow (i guess) workaround could be:
>>>
>>> "test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
>>>
>>> vs the new one:
>>>
>>> "test".toUpper.Identity!(a => "This is a " ~ a).writeln;
>>
>> Shouldn't be slow, your just giving the optimiser some work to do*, but you're always better off with the second one.
>>
>> *Assuming a good optimiser. dmd won't work this out.
>
> s/your/you're

Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version.

Anyway I think I'm going to rename it "apply". :)

"test".toUpper.apply!(a => "This is a " ~ a).writeln;

It sounds better.
April 28, 2015
On Tuesday, 28 April 2015 at 02:36:38 UTC, Vladimir Panteleev wrote:
> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/

Very nice. There is also a similar package protected template in std.typetuple, `Alias`. I used it a lot but last applicability case with UFCS chain didn't come to my mind. It looks very elegant.

I had plans to introduce it as a public helper in std.meta under the name `Symbol`, would that make sense?
April 28, 2015
On Tuesday, 28 April 2015 at 10:07:43 UTC, Andrea Fontana wrote:
> On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
>> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
>
> A very slow (i guess) workaround could be:
>
> "test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
>
> vs the new one:
>
> "test".toUpper.Identity!(a => "This is a " ~ a).writeln;

Using std.functional:

"test".toUpper.unaryFun!(a => "This is a " ~ a).writeln;
« First   ‹ Prev
1 2 3 4