Re: The amazing template which does nothing
On Wednesday, 29 April 2015 at 14:18:49 UTC, Iain Buclaw wrote: On 29 April 2015 at 14:50, John Colvin via Digitalmars-d digitalmars-d@puremagic.com wrote: On Wednesday, 29 April 2015 at 12:07:58 UTC, Vladimir Panteleev wrote: On Wednesday, 29 April 2015 at 07:00:15 UTC, John Colvin wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Ah, my bad! I know Iain was involved so I thought it had GDC as well :) d.godbolt.org now has the latest release as default. I take it you've been speaking to the site maintainer? :o) Looks like he downloaded the binary off gdcproject.org? Yes and yes.
Re: The amazing template which does nothing
On 30 April 2015 at 15:01, John Colvin via Digitalmars-d digitalmars-d@puremagic.com wrote: On Wednesday, 29 April 2015 at 14:18:49 UTC, Iain Buclaw wrote: On 29 April 2015 at 14:50, John Colvin via Digitalmars-d digitalmars-d@puremagic.com wrote: On Wednesday, 29 April 2015 at 12:07:58 UTC, Vladimir Panteleev wrote: On Wednesday, 29 April 2015 at 07:00:15 UTC, John Colvin wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Ah, my bad! I know Iain was involved so I thought it had GDC as well :) d.godbolt.org now has the latest release as default. I take it you've been speaking to the site maintainer? :o) Looks like he downloaded the binary off gdcproject.org? Yes and yes. You could have waited a month for gdc-5 to come out of experimental... https://packages.debian.org/experimental/gdc-5
Re: The amazing template which does nothing
On Tuesday, 28 April 2015 at 22:29:40 UTC, Steven Schveighoffer wrote: On 4/28/15 6:00 PM, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 21:42:04 UTC, Steven Schveighoffer wrote: On 4/27/15 10:36 PM, Vladimir Panteleev wrote: http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/ Very cool. Just a grammar nit, an UFCS should be a UFCS. Fixed, thanks. (I always found this rule counter-intuitive... u is a vowel dangit!) And in most cases, 'an' is correct. It's only when it makes a you sound (and if you spell out your acronyms, 'U' does), when you want to use 'a' :) an upsetting rule ('uh') an uber-cool language ('oo') a unique grammar problem ('you') -Steve Yeah, because the sound in `you` or the letter u is not a full vowel but a semi-vowel /j/ (cf. German `ja`), also: a voiced palatal approximant: https://en.wikipedia.org/wiki/Palatal_approximant Whenever a phonetic /u(:)/ becomes a /ju(:)/ (for whatever reason), rules for vowels no longer apply, simply because it is (phonetically speaking) no longer vowel, e.g. an + V = a + /j/. Cf a utilitarian point of view (*an utilitarian) /juː/ The spelling rule upsets you, because there is a mismatch between what you see on the page and how you pronounce it (vowel vs. consonant/semi-vowel). It also works the other way around: - an STL expert - a PhD student s describes a consonant but is pronounced with a vowel here /es/. Thus, you have to write `an`. Just follow your natural way of speaking and you'll be fine. Read it out to yourself. And let's be honest, it sounds really crap when you read an UFCS, bahhh!
Re: The amazing template which does nothing
On Wednesday, 29 April 2015 at 06:56:37 UTC, Nikolay wrote: 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 good article little mistake: return from void function: /// Search a website for something, and parse the /// first search result's webpage. void getItemInfo(string itemName) { // Let's go! First, construct the URL. return (http://www.example.com/search?q=; ~ encodeComponent(itemName)) ... Fixed, thanks. Though, you technically still can use return expression in a void function, as long as expression's type is void :)
Re: The amazing template which does nothing
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 good article little mistake: return from void function: /// Search a website for something, and parse the /// first search result's webpage. void getItemInfo(string itemName) { // Let's go! First, construct the URL. return (http://www.example.com/search?q=; ~ encodeComponent(itemName)) ...
Re: The amazing template which does nothing
On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD.
Re: The amazing template which does nothing
On 29 Apr 2015 09:05, John Colvin via Digitalmars-d digitalmars-d@puremagic.com wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Well it's using frontend 2.055, which I guess would put it at gdc-4.6 in Debian repos.
Re: The amazing template which does nothing
On Wednesday, 29 April 2015 at 07:00:15 UTC, John Colvin wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Ah, my bad! I know Iain was involved so I thought it had GDC as well :)
Re: The amazing template which does nothing
On 29 April 2015 at 14:07, Vladimir Panteleev via Digitalmars-d digitalmars-d@puremagic.com wrote: On Wednesday, 29 April 2015 at 07:00:15 UTC, John Colvin wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Ah, my bad! I know Iain was involved so I thought it had GDC as well :) DMD and GDC don't generate compatible outputs, so it's not that straightforward to have both together. ;-) d.godbolt.org is better than asm.dlang.org because GDC emits assembly, you have more information to play around with (and syntax highlighting works thanks to .file and .loc assembler directives). asm.dlang.org is a basterdised version that removes all features because DMD emits object code, and there is no useful information you can pull from objdump. It is nice that you can test the latest daily on asm.dlang.org though... Iain.
Re: The amazing template which does nothing
On Wednesday, 29 April 2015 at 12:07:58 UTC, Vladimir Panteleev wrote: On Wednesday, 29 April 2015 at 07:00:15 UTC, John Colvin wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Ah, my bad! I know Iain was involved so I thought it had GDC as well :) d.godbolt.org now has the latest release as default.
Re: The amazing template which does nothing
On 29 April 2015 at 12:16, John Colvin via Digitalmars-d digitalmars-d@puremagic.com wrote: On Wednesday, 29 April 2015 at 07:49:34 UTC, Iain Buclaw wrote: On 29 Apr 2015 09:05, John Colvin via Digitalmars-d digitalmars-d@puremagic.com wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Well it's using frontend 2.055, which I guess would put it at gdc-4.6 in Debian repos. Did you check the dropdown menu? There's 4.9 in there. Hopefully the latest release from gdcproject.org will be added in the next couple of days Ah! I was on my phone and didn't notice. :-O
Re: The amazing template which does nothing
On Wednesday, 29 April 2015 at 07:49:34 UTC, Iain Buclaw wrote: On 29 Apr 2015 09:05, John Colvin via Digitalmars-d digitalmars-d@puremagic.com wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Well it's using frontend 2.055, which I guess would put it at gdc-4.6 in Debian repos. Did you check the dropdown menu? There's 4.9 in there. Hopefully the latest release from gdcproject.org will be added in the next couple of days
Re: The amazing template which does nothing
On 29 April 2015 at 14:50, John Colvin via Digitalmars-d digitalmars-d@puremagic.com wrote: On Wednesday, 29 April 2015 at 12:07:58 UTC, Vladimir Panteleev wrote: On Wednesday, 29 April 2015 at 07:00:15 UTC, John Colvin wrote: On Tuesday, 28 April 2015 at 21:19:53 UTC, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org d.godbolt.org (note .org not .com) works fine and will be updated to the latest GDC shortly. asm.dlang.org only has DMD. Ah, my bad! I know Iain was involved so I thought it had GDC as well :) d.godbolt.org now has the latest release as default. I take it you've been speaking to the site maintainer? :o) Looks like he downloaded the binary off gdcproject.org?
Re: The amazing template which does nothing
On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: 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. The d.godbolt.org compilers seem a little out of date. I have found problems with their codegen/optimisation that doesn't happen in more recent versions. ldc 0.15.2 based on llvm 3.5.1 reduces both chains to identical asm.
Re: The amazing template which does nothing
On Tuesday, 28 April 2015 at 22:24:53 UTC, Max Samukha wrote: 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/ A truly polymorphic identity function in D would be more involved: template id(a...) if (a.length == 1) { static if (__traits(compiles, { alias id = a[0]; } )) alias id = a[0]; else enum id = a[0]; } static assert(is(id!int == int)); static assert(id!1 == 1); Also, an 'isEqual' template would be needed to unify 'isSame', 'is' and '=='. Actually I do find more specialized names/implementations useful in this case. For example, just the fact that you use `unaryFun!(a = a)` instead of `Identity!(a = a)` makes code more readable and intention clear even if effect is the same.
Re: The amazing template which does nothing
On Tuesday, 28 April 2015 at 19:32:40 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/ Went to post on reddit, was there already: http://www.reddit.com/r/programming/comments/345zw3/the_amazing_template_that_does_nothing/ I've also posted on these other sites: Thank you, though the article is kinda targeted at experienced D developers. As the redditors have been quick to point out, most of these are basically workarounds for grammar quirks.
Re: The amazing template which does nothing
On Tuesday, 28 April 2015 at 10:24:27 UTC, Andrea Fontana wrote: Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version. d.godbolt.com is dead, use asm.dlang.org
Re: The amazing template which does nothing
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/ A truly polymorphic identity function in D would be more involved: template id(a...) if (a.length == 1) { static if (__traits(compiles, { alias id = a[0]; } )) alias id = a[0]; else enum id = a[0]; } static assert(is(id!int == int)); static assert(id!1 == 1); Also, an 'isEqual' template would be needed to unify 'isSame', 'is' and '=='.
Re: The amazing template which does nothing
On 4/28/15 6:00 PM, Vladimir Panteleev wrote: On Tuesday, 28 April 2015 at 21:42:04 UTC, Steven Schveighoffer wrote: On 4/27/15 10:36 PM, Vladimir Panteleev wrote: http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/ Very cool. Just a grammar nit, an UFCS should be a UFCS. Fixed, thanks. (I always found this rule counter-intuitive... u is a vowel dangit!) And in most cases, 'an' is correct. It's only when it makes a you sound (and if you spell out your acronyms, 'U' does), when you want to use 'a' :) an upsetting rule ('uh') an uber-cool language ('oo') a unique grammar problem ('you') -Steve
Re: The amazing template which does nothing
On 4/27/15 10:36 PM, Vladimir Panteleev wrote: http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/ Very cool. Just a grammar nit, an UFCS should be a UFCS. -Steve
Re: The amazing template which does nothing
On Tuesday, 28 April 2015 at 21:42:04 UTC, Steven Schveighoffer wrote: On 4/27/15 10:36 PM, Vladimir Panteleev wrote: http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/ Very cool. Just a grammar nit, an UFCS should be a UFCS. Fixed, thanks. (I always found this rule counter-intuitive... u is a vowel dangit!)
Re: The amazing template which does nothing
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.
Re: The amazing template which does nothing
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
Re: The amazing template which does nothing
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;
Re: The amazing template which does nothing
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
Re: The amazing template which does nothing
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.
Re: The amazing template which does nothing
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.
Re: The amazing template which does nothing
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?
Re: The amazing template which does nothing
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;
Re: The amazing template which does nothing
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.
Re: The amazing template which does nothing
On 4/27/15 7:36 PM, Vladimir Panteleev wrote: http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/ Went to post on reddit, was there already: http://www.reddit.com/r/programming/comments/345zw3/the_amazing_template_that_does_nothing/ I've also posted on these other sites: https://news.ycombinator.com/newest https://twitter.com/D_Programming/status/593135475537223680 https://www.facebook.com/dlang.org/posts/1059305784083102 Andrei