On Tuesday, 18 October 2016 at 15:41:29 UTC, Jesse Phillips wrote:
On Monday, 17 October 2016 at 20:13:19 UTC, Karabuta wrote:
I would suggest they remove all templates and make it its own example.

* Basic functional/ranges example = map, filter, reduce


* basic helloworld = write the string "Hello, World!"

Template (implicit)

* Basic sort example


* basic maths example

Template at times (implicit)

* basic UFCS example

Works with templates

It is very hard to use D and not instantiate a template for the "basics."

I've shown this to a colleague of mine a few days ago: he was super confused by the ! operator. Then I told him it was D's syntax for templates and everything made sense.

You can change the example to (here i left the same code of the original one, but I agree with what the other said about it)

`// Round floating point numbers
import std.algorithm, std.conv, std.functional,
    std.math, std.regex, std.stdio;

alias round = pipe!(to!real, std.math.round, to!string);
static reFloatingPoint = ctRegex!`[0-9]+\.[0-9]+`;

void main()
    // Replace anything that looks like a real
    // number with the rounded equivalent.
        .map!(l => l.replaceAll!(c => c.hit.round)

If someone click on Explain, show
This example shows how easy it is to perform operations on data in D in a quick overview of some general concepts which are widespread in D. You can see the byLine function being called without parenthesis because it doesn't take any parameters in this case, the map[1] template being used with UFCS [2], taking a lambda as templated parameter with D template syntax (template_name!(template_parameters)(runtime_parameters) )[3], the "each" template called with writeln as template parameter without parenthesis because it's the only parameter taken.
To learn more about pipelining in D check out [4]

[1] https://dlang.org/phobos/std_algorithm_iteration.html#.map
[2] http://ddili.org/ders/d.en/ufcs.html
[3] https://dlang.org/spec/template.html
[4] page about that

Having 10 lines explaining what's going on in the code and providing links to understand better can hook up a new user way better than letting them do guess work. Moreover you can start showing the documentation already, so they can start to be familiar with where to search stuff

Reply via email to