www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Three Cool Things about D

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/

https://www.facebook.com/dlang.org/posts/1192267587453587

https://twitter.com/D_Programming/status/678989872367988741


Andrei
Dec 21 2015
next sibling parent Jack Stouffer <jack jackstouffer.com> writes:
On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu 
wrote:
 https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/

 https://www.facebook.com/dlang.org/posts/1192267587453587

 https://twitter.com/D_Programming/status/678989872367988741


 Andrei
In the future, you should put your name in the title as it will probably get more votes that way.
Dec 21 2015
prev sibling next sibling parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu 
wrote:
 https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/
Great motivation as always! Thx!
Dec 22 2015
prev sibling next sibling parent reply David Nadlinger <code klickverbot.at> writes:
On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu 
wrote:
 https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/
By the way, even though I wholeheartedly share your sentiment regarding those "functional" examples, I found it to be an interesting example for the power of modern optimizers that LDC manages to compile this --- ulong factorial(this n) { return n <= 1 ? 1 : n * factorial(n - 1); } --- to this: --- __D4test9factorialFkZm: mov eax, 1 cmp edi, 2 jb LBB0_7 mov ecx, edi lea edx, [rdi + 7] add edi, -2 mov eax, 1 test dl, 7 je LBB0_4 and edx, 7 neg edx mov eax, 1 .align 4, 0x90 LBB0_3: imul rax, rcx dec rcx inc edx jne LBB0_3 LBB0_4: cmp edi, 7 jb LBB0_7 add rcx, -3 .align 4, 0x90 LBB0_6: lea rdx, [rcx + 3] imul rdx, rax lea rax, [rcx + 2] lea rsi, [rcx + 1] imul rax, rsi imul rax, rdx lea rdx, [rcx - 1] imul rdx, rcx lea rsi, [rcx - 2] imul rsi, rdx imul rsi, rax lea rax, [rcx - 3] lea rdx, [rcx - 4] imul rax, rdx imul rax, rsi add rcx, -8 lea edx, [rcx + 3] cmp edx, 1 ja LBB0_6 LBB0_7: ret --- Not sure about how it arrives at the crazily unrolled loop, but no recursion in sight anymore. — David
Dec 22 2015
next sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 12/22/15 1:29 PM, David Nadlinger wrote:

 ---
 ulong factorial(this n) {
      return n <= 1 ? 1 : n * factorial(n - 1);
 }
 ---
Am I missing some new feature here? What does the 'this' mean? -Steve
Dec 22 2015
parent David Nadlinger <code klickverbot.at> writes:
On Tuesday, 22 December 2015 at 19:07:55 UTC, Steven 
Schveighoffer wrote:
 Am I missing some new feature here? What does the 'this' mean?
I have no idea, this must have been some sort of weird copy/paste or auto-correct mistake on my side. It's supposed to be "uint", as in Andrei's talk. — David
Dec 22 2015
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 12/22/2015 10:29 AM, David Nadlinger wrote:
 Not sure about how it arrives at the crazily unrolled loop, but no recursion in
 sight anymore.
It's doing tail recursion optimization, which turns the recursion into a loop. Then the loop is unrolled 8 times.
Dec 22 2015
next sibling parent David Nadlinger <code klickverbot.at> writes:
On Wednesday, 23 December 2015 at 01:07:57 UTC, Walter Bright 
wrote:
 On 12/22/2015 10:29 AM, David Nadlinger wrote:
 Not sure about how it arrives at the crazily unrolled loop, 
 but no recursion in
 sight anymore.
It's doing tail recursion optimization, which turns the recursion into a loop.
The recursive call is not quite a tail call by itself, which is what Andrei pointed out using that example. But yes, that's what happens.
 Then the loop is unrolled 8 times.
Sure thing. I was rather surprised to see that happen given that I only compiled with -O1, though, as it seems to be quite an aggressive optimization. — David
Dec 22 2015
prev sibling parent deadalnix <deadalnix gmail.com> writes:
On Wednesday, 23 December 2015 at 01:07:57 UTC, Walter Bright 
wrote:
 On 12/22/2015 10:29 AM, David Nadlinger wrote:
 Not sure about how it arrives at the crazily unrolled loop, 
 but no recursion in
 sight anymore.
It's doing tail recursion optimization, which turns the recursion into a loop. Then the loop is unrolled 8 times.
You can't to tail recursion in it's basic form because there is a multiplication at the end.
Dec 23 2015
prev sibling next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/21/2015 09:28 AM, Andrei Alexandrescu wrote:
 https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/


 https://www.facebook.com/dlang.org/posts/1192267587453587

 https://twitter.com/D_Programming/status/678989872367988741


 Andrei
Two unnecessary pedantic corrections: - One of the earlier slides has "Voldermort" with an extra 'r'. It should be Voldemort. - At the end of one of the optimization presentations you said that the behaviour of unsigned integer overflow and *underflow* are well defined. Although what you meant is clear and that I've been using "underflow" in the same meaning until very recently, I now know that underflow is a condition only for floating point types. Copying from Wikipedia, "Arithmetic underflow can occur when the true result of a floating point operation is smaller in magnitude (that is, closer to zero) than the smallest value representable as a normal floating point number in the target datatype." Ali
Dec 22 2015
prev sibling next sibling parent Jakob Jenkov <jakob jenkov.com> writes:
On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu 
wrote:
 https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/

 https://www.facebook.com/dlang.org/posts/1192267587453587

 https://twitter.com/D_Programming/status/678989872367988741


 Andrei
Interesting talk :-) Watched it while cooking.
Dec 23 2015
prev sibling next sibling parent reply Abdulhaq <alynch4047 gmail.com> writes:
On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu 
wrote:
 https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/

 https://www.facebook.com/dlang.org/posts/1192267587453587

 https://twitter.com/D_Programming/status/678989872367988741


 Andrei
A clip of the comedian that Andrei refers to can be seen here: https://www.youtube.com/watch?v=uEY58fiSK8E
Dec 23 2015
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/23/2015 09:06 AM, Abdulhaq wrote:
 A clip of the comedian that Andrei refers to can be seen here:

 https://www.youtube.com/watch?v=uEY58fiSK8E
I love that bit! -- Andrei
Dec 23 2015
prev sibling parent reply Joakim <dlang joakim.fea.st> writes:
On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu 
wrote:
 https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/

 https://www.facebook.com/dlang.org/posts/1192267587453587

 https://twitter.com/D_Programming/status/678989872367988741


 Andrei
Just watched the whole video, even though I've seen a prior version of this talk. It was different enough in the jokes and delivery that I still enjoyed it. Some notes: 1. Saying "Anywho" to segue to a new topic seems to be a verbal tic of Andrei's now. 2. It's claimed that scoped imports sped up D compilation: has this been measured? It would help if measurements were cited, as done for compile-time regex performance at the end. 3. It's better that you show usage examples of a PEGGED grammar now, as opposed to a previous talk that ended with the mixin slide, but I think it'd be best if you actually worked a toy example out and showed the generated D code, to really drive the point home. Even better if it wasn't something you could trivially write in D itself, like the arithmetic example you gave.
Dec 25 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/26/15 12:29 AM, Joakim wrote:
 1. Saying "Anywho" to segue to a new topic seems to be a verbal tic of
 Andrei's now.

 2. It's claimed that scoped imports sped up D compilation: has this been
 measured?  It would help if measurements were cited, as done for
 compile-time regex performance at the end.

 3. It's better that you show usage examples of a PEGGED grammar now, as
 opposed to a previous talk that ended with the mixin slide, but I think
 it'd be best if you actually worked a toy example out and showed the
 generated D code, to really drive the point home.  Even better if it
 wasn't something you could trivially write in D itself, like the
 arithmetic example you gave.
Thanks for the feedback! I'll keep it in mind. -- Andrei
Dec 26 2015
parent reply Rory McGuire via Digitalmars-d-announce writes:
I have a full Jade template parser in Pegged that I just need to finish the
d code gen part, could it be an interesting example?
On 26 Dec 2015 20:10, "Andrei Alexandrescu via Digitalmars-d-announce" <
digitalmars-d-announce puremagic.com> wrote:

 On 12/26/15 12:29 AM, Joakim wrote:

 1. Saying "Anywho" to segue to a new topic seems to be a verbal tic of
 Andrei's now.

 2. It's claimed that scoped imports sped up D compilation: has this been
 measured?  It would help if measurements were cited, as done for
 compile-time regex performance at the end.

 3. It's better that you show usage examples of a PEGGED grammar now, as
 opposed to a previous talk that ended with the mixin slide, but I think
 it'd be best if you actually worked a toy example out and showed the
 generated D code, to really drive the point home.  Even better if it
 wasn't something you could trivially write in D itself, like the
 arithmetic example you gave.
Thanks for the feedback! I'll keep it in mind. -- Andrei
Dec 26 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/26/15 1:35 PM, Rory McGuire via Digitalmars-d-announce wrote:
 I have a full Jade template parser in Pegged that I just need to finish
 the d code gen part, could it be an interesting example?
Yes. How well-known is Jade? -- Andrei
Dec 26 2015
next sibling parent reply Daniel Kozak via Digitalmars-d-announce writes:
https://strongloop.com/strongblog/compare-javascript-templates-jade-mustach=
e-dust/

Andrei Alexandrescu via Digitalmars-d-announce=20
<digitalmars-d-announce puremagic.com> napsal So, pro 26, 2015 v 8=E2=88=B6=
58=20
:
 On 12/26/15 1:35 PM, Rory McGuire via Digitalmars-d-announce wrote:
 I have a full Jade template parser in Pegged that I just need to=20
 finish
 the d code gen part, could it be an interesting example?
=20 Yes. How well-known is Jade? -- Andrei
=
Dec 26 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/26/15 4:17 PM, Daniel Kozak via Digitalmars-d-announce wrote:
 https://strongloop.com/strongblog/compare-javascript-templates-jade-mustache-dust/

 Andrei Alexandrescu via Digitalmars-d-announce
 <digitalmars-d-announce puremagic.com> napsal So, pro 26, 2015 v 8∶58 :
 On 12/26/15 1:35 PM, Rory McGuire via Digitalmars-d-announce wrote:

     I have a full Jade template parser in Pegged that I just need to
     finish the d code gen part, could it be an interesting example?

 Yes. How well-known is Jade? -- Andrei
That looks pretty cool! -- Andrei
Dec 27 2015
parent Jacob Carlborg <doob me.com> writes:
On 2015-12-27 17:23, Andrei Alexandrescu wrote:

 That looks pretty cool! -- Andrei
It's based on Haml which is pretty well known as well. -- /Jacob Carlborg
Dec 28 2015
prev sibling parent reply Rory McGuire via Digitalmars-d-announce writes:
On 26 Dec 2015 22:00, "Andrei Alexandrescu via Digitalmars-d-announce" <
digitalmars-d-announce puremagic.com> wrote:
 On 12/26/15 1:35 PM, Rory McGuire via Digitalmars-d-announce wrote:
 I have a full Jade template parser in Pegged that I just need to finish
 the d code gen part, could it be an interesting example?
Yes. How well-known is Jade? -- Andrei
It is well known. I thought handlebars was used more but those github numbers say different. Vibe.d had a template engine called diet which is almost like Jade. It is also completed so you might prefer that as an example.
Dec 26 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/27/15 1:27 AM, Rory McGuire via Digitalmars-d-announce wrote:
 On 26 Dec 2015 22:00, "Andrei Alexandrescu via Digitalmars-d-announce"
 <digitalmars-d-announce puremagic.com
 <mailto:digitalmars-d-announce puremagic.com>> wrote:
  >
  > On 12/26/15 1:35 PM, Rory McGuire via Digitalmars-d-announce wrote:
  >>
  >> I have a full Jade template parser in Pegged that I just need to finish
  >> the d code gen part, could it be an interesting example?
  >
  >
  > Yes. How well-known is Jade? -- Andrei

 It is well known. I thought handlebars was used more but those github
 numbers say different.

 Vibe.d had a template engine called diet which is almost like Jade. It
 is also completed so you might prefer that as an example.
Either or both would be awesome to express with Pegged. -- Andrei
Dec 27 2015
next sibling parent Rory McGuire via Digitalmars-d-announce writes:
On 27 Dec 2015 6:25 PM, "Andrei Alexandrescu via Digitalmars-d-announce" <
digitalmars-d-announce puremagic.com> wrote:
 On 12/27/15 1:27 AM, Rory McGuire via Digitalmars-d-announce wrote:
[snip]
 Vibe.d had a template engine called diet which is almost like Jade. It
 is also completed so you might prefer that as an example.
Either or both would be awesome to express with Pegged. -- Andrei
I'm working on the output part now while it's the holidays. Will share once I've got my test template translating to html as a demo.
Dec 28 2015
prev sibling parent reply Rory McGuire via Digitalmars-d-announce writes:
On Mon, Dec 28, 2015 at 5:24 PM, Rory McGuire <rjmcguire gmail.com> wrote:

 On 27 Dec 2015 6:25 PM, "Andrei Alexandrescu via Digitalmars-d-announce" <
 digitalmars-d-announce puremagic.com> wrote:
 On 12/27/15 1:27 AM, Rory McGuire via Digitalmars-d-announce wrote:
[snip]
 Vibe.d had a template engine called diet which is almost like Jade. It
 is also completed so you might prefer that as an example.
Either or both would be awesome to express with Pegged. -- Andrei
I'm working on the output part now while it's the holidays. Will share once I've got my test template translating to html as a demo.
A little teaser, this is the output of the app and runtime and/or compile time: <!DOCTYPE html><!--[if IE 8]><html lang="en" class="lt-ie9"></html><![endif]--><html lang="en"><head><title>Index of Demo</title><style>body { margin: 0px; background-color: #eee; }</style></head><body class="base-css" ng-app="MyApp" ng-controller="CtrlII"> <!-- this is the actual displayed content --><p id="" p-form-hook="yes" marked="null">This is the index.jade <i>paragraph</i> that<b>test</b> continues <i>on</i> multiplelines goto <a target="_blank" href=" https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade">Jade Reference</a> <!-- TODO: should allow empty lines in PipedText or at least show an error --> <!-- | -->to see examples of interpolation</p><ul isit="true"><li class="one-css two-css"></li></ul><div class="img-holder"><img class="image" src="logo2.gif" style="padding: 0px;background: red"></img></div></body><woot id="content1">as2df<woot2 id="woot2" class="c1,c2">as3dfas3df</woot2><woot3 class="{&quote;active&quote;:false}"></woot3><p>This is the text in footer block</p></woot></html><merrrt></merrrt><p>You are logged in</p><ul><li>3: three</li><li>2: two</li><li>1: one</li></ul><li>1</li><li>2</li><li>3</li><p>you have 42 friends</p><ul><li>foo</li><li>bar</li><li>baz</li></ul><ul><li>foo</li><li>bar</li><li>baz</li></ul><ul><li class="pet">cat</li><li class="pet">dog</li><li class="pet">pig</li></ul><div class="article"><div class="article-wrapper"><h1>Hello world</h1><p>No content provided</p></div></div><div class="article"><div class="article-wrapper"><h1>Hello world</h1><p>This is my</p><p>Amazing article</p></div></div><a class="btn" href="/foo">foo</a><a href="/foo">foo</a><ul id="my-list"><li>1</li><li>2</li><li>3</li><li>4</li></ul><p>If you take a look at this page's source <a target="_blank" href=" https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade">on GitHub</a>, you'll see several places where the tag interpolation operator is used like so. .quote // this is raw text so the .quote means nothing to jade, only string and tag interpolation works here p Joel: <b>risky</b></p><p>This is supposed to just be text inside a p characters</p><!-- Following is as4df, its the last tag --><as4df></as4df> Translated from these files: *=========================* extends second_layout.jade block title title Index of Demo block content // this is the actual displayed content p(id="", p-form-hook=some_d_var ? "yes" :"no", marked) This is the https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade") Jade Reference] // TODO: should allow empty lines in PipedText or at least show an error //| | to see examples of interpolation ul(isit=some_other_d_var == "woot") .img-holder img.image(src="logo2.gif", style={background: "red", padding: "0px"})/ *============================* extends second_layout.jade block title title Index of Demo block content // this is the actual displayed content p(id="", p-form-hook=some_d_var ? "yes" :"no", marked) This is the https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade") Jade Reference] // TODO: should allow empty lines in PipedText or at least show an error //| | to see examples of interpolation ul(isit=some_other_d_var == "woot") .img-holder img.image(src="logo2.gif", style={background: "red", padding: "0px"})/ rmcguire rmcguire-hx:~/Projects/jade$ cat views/second_layout.jade extends base_layout.jade block footer p This is the text in footer block *===================================* doctype html - auto currentUrl = "/"; - auto riskyBusiness = "<b>risky</b>"; <!--[if IE 8]> html(lang="en", class="lt-ie9") <![endif]--> - bool some_d_var = true; - string some_other_d_var = "woot"; html(lang="en") head block title title Page Title Here style include style.css body.base-css(ng-app="MyApp", ng-controller="CtrlII") block content // this is the displayed content p(id="", p-form-hook=some_d_var ? "yes" :"no", marked) This is a paragraph | That continues on | multiple lines ul(isit=some_other_d_var == "woot") .img-holder img.image(src="logo.gif", style={background: "red", padding: "0px"})/ woot#content1 as2df #woot2(class=["c1", "c2"]) as3dfas3df woot3(class={active: currentUrl == "/about"}) block footer p Placeholder footer block - var host = "remotehost"; - var user = var.emptyObject; if "localhost" == host div#foo(data-bar="foo", goot-one)&attributes({"data-cew": "baer", "ng-show": 1234}) //- include:markdown ./includes/footer.jade else merrrt unless user.isAnonymous p You are logged in //- :markdown //- I often like including markdown documents. ul - import std.conv; each index, val in [1:"one",2:"two",3:"three"] li= to!string(index) ~": "~ val - int n=1; while n < 4 li= n++ - auto friends = 42; case friends when 0 when 1 p you have very few friends //- Declaration mixin list ul li foo li bar li baz //- Use +list +list mixin pet(name) li.pet= name ul +pet("cat") +pet("dog") +pet("pig") mixin article(title) .article .article-wrapper h1= title if block block else p No content provided +article("Hello world") +article("Hello world") p This is my p Amazing article mixin link(href, name) //- attributes == {class: "btn"} a(class!=attributes["class"], href=href)= name +link("/foo", "foo")(class="btn") mixin link2(href, name) a(href=href)&attributes(attributes)= name +link2("/foo", "foo")(class="btn") mixin list2(id, ...items) ul(id=id) each item in items li= item +list2("my-list", 1, 2, 3, 4) p. https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade") on GitHub], you'll see several places where the tag interpolation operator is used like so. .quote // this is raw text so the .quote means nothing to jade, only string and tag interpolation works here p Joel: !{riskyBusiness} p. This is supposed to just be text inside a p tag. - import std.uni : toUpper; - string msg = "not my inside voice"; // Following is as4df, its the last tag as4df
Jan 07 2016
parent reply Jack Stouffer <jack jackstouffer.com> writes:
On Friday, 8 January 2016 at 00:32:05 UTC, Rory McGuire wrote:
 On Mon, Dec 28, 2015 at 5:24 PM, Rory McGuire 
 <rjmcguire gmail.com> wrote:

 On 27 Dec 2015 6:25 PM, "Andrei Alexandrescu via 
 Digitalmars-d-announce" < 
 digitalmars-d-announce puremagic.com> wrote:
 On 12/27/15 1:27 AM, Rory McGuire via Digitalmars-d-announce 
 wrote:
[snip]
 Vibe.d had a template engine called diet which is almost 
 like Jade. It is also completed so you might prefer that as 
 an example.
Either or both would be awesome to express with Pegged. -- Andrei
I'm working on the output part now while it's the holidays. Will share once I've got my test template translating to html as a demo.
A little teaser, this is the output of the app and runtime
Can you post all of the D code on github as well, seeing as the forum strips your code formatting, making it very hard to read.
Jan 07 2016
parent Rory McGuire via Digitalmars-d-announce writes:
Some of the template support code is still in the app.d file. And I mean to
rename some  of the functions etc. You can access all the output in
current_output.txt and the template used is index.jade.

github.com/rjmcguire/jaded
On 08 Jan 2016 04:45, "Jack Stouffer via Digitalmars-d-announce" <
digitalmars-d-announce puremagic.com> wrote:

 On Friday, 8 January 2016 at 00:32:05 UTC, Rory McGuire wrote:

 On Mon, Dec 28, 2015 at 5:24 PM, Rory McGuire <rjmcguire gmail.com>
 wrote:


 On 27 Dec 2015 6:25 PM, "Andrei Alexandrescu via Digitalmars-d-announce"
 < digitalmars-d-announce puremagic.com> wrote:
 On 12/27/15 1:27 AM, Rory McGuire via Digitalmars-d-announce > wrote:
[snip]
 Vibe.d had a template engine called diet which is almost >> like
Jade. It is also completed so you might prefer that as >> an example.
 Either or both would be awesome to express with Pegged. -- > Andrei
I'm working on the output part now while it's the holidays. Will share once I've got my test template translating to html as a demo. A little teaser, this is the output of the app and runtime
Can you post all of the D code on github as well, seeing as the forum strips your code formatting, making it very hard to read.
Jan 07 2016