From ba7b8a613b445d1ee79ad190ceed6a008595116c Mon Sep 17 00:00:00 2001 From: Jana Trestikova Date: Fri, 23 Oct 2015 06:55:00 +0200 Subject: Fix Typos --- d.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index 80c1dc65..3915b005 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -70,7 +70,7 @@ void main() { ``` We can define new types with `struct`, `class`, `union`, and `enum`. Structs and unions -are passed to functions by value (i.e. copied) and classes are passed by reference. Futhermore, +are passed to functions by value (i.e. copied) and classes are passed by reference. Furthermore, we can use templates to parameterize all of these on both types and values! ```c -- cgit v1.2.3 From 9aad08bf78196758a568ec1272c94029221c2dd5 Mon Sep 17 00:00:00 2001 From: Amru Eliwat Date: Fri, 23 Oct 2015 23:13:29 -0700 Subject: Fixed typos for 'overriding' and 'reference' and fixed formatting issue that may have caused confusion --- d.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index 80c1dc65..6f3710ab 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -199,8 +199,8 @@ our getter and setter methods, and keep the clean syntax of accessing members directly! Other object-oriented goodies at our disposal -include `interface`s, `abstract class`es, -and `override`ing methods. D does inheritance just like Java: +include interfaces, abstract classes, +and overriding methods. D does inheritance just like Java: Extend one class, implement as many interfaces as you please. We've seen D's OOP facilities, but let's switch gears. D offers @@ -247,7 +247,7 @@ void main() { // and take advantage of as many cores as we have available. auto arr = new double[1_000_000]; - // Use an index, and an array element by referece, + // Use an index, and an array element by reference, // and just call parallel on the array! foreach(i, ref elem; parallel(arr)) { ref = sqrt(i + 1.0); -- cgit v1.2.3 From 1391eed837546e442eeaa48bfae9504b999b8c58 Mon Sep 17 00:00:00 2001 From: Dan Ellis Date: Tue, 10 Nov 2015 23:31:16 -0800 Subject: Fix variable name typo in dlang examples. --- d.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index 6f3710ab..9ebba385 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -53,15 +53,15 @@ void main() { // For and while are nice, but in D-land we prefer 'foreach' loops. // The '..' creates a continuous range, including the first value // but excluding the last. - foreach(i; 1..1_000_000) { + foreach(n; 1..1_000_000) { if(n % 2 == 0) - writeln(i); + writeln(n); } // There's also 'foreach_reverse' when you want to loop backwards. - foreach_reverse(i; 1..int.max) { + foreach_reverse(n; 1..int.max) { if(n % 2 == 1) { - writeln(i); + writeln(n); } else { writeln("No!"); } -- cgit v1.2.3 From 0737d9be0bfdedc11842b39f8422123ac329f524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Polykanine=20A=2EK=2EA=2E=20Menelion=20Elens=C3=BA?= =?UTF-8?q?l=C3=AB?= Date: Wed, 2 Dec 2015 21:59:12 +0200 Subject: Resolving conflict in #1710 --- d.html.markdown | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index 9ebba385..ecb9e3ac 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -218,7 +218,7 @@ void main() { // from 1 to 100. Easy! // Just pass lambda expressions as template parameters! - // You can pass any old function you like, but lambdas are convenient here. + // You can pass any function you like, but lambdas are convenient here. auto num = iota(1, 101).filter!(x => x % 2 == 0) .map!(y => y ^^ 2) .reduce!((a, b) => a + b); @@ -228,7 +228,7 @@ void main() { ``` Notice how we got to build a nice Haskellian pipeline to compute num? -That's thanks to a D innovation know as Uniform Function Call Syntax. +That's thanks to a D innovation know as Uniform Function Call Syntax (UFCS). With UFCS, we can choose whether to write a function call as a method or free function call! Walter wrote a nice article on this [here.](http://www.drdobbs.com/cpp/uniform-function-call-syntax/232700394) @@ -238,21 +238,23 @@ is of some type A on any expression of type A as a method. I like parallelism. Anyone else like parallelism? Sure you do. Let's do some! ```c +// Let's say we want to populate a large array with the square root of all +// consecutive integers starting from 1 (up until the size of the array), and we +// want to do this concurrently taking advantage of as many cores as we have +// available. + import std.stdio; import std.parallelism : parallel; import std.math : sqrt; void main() { - // We want take the square root every number in our array, - // and take advantage of as many cores as we have available. + // Create your large array auto arr = new double[1_000_000]; - // Use an index, and an array element by reference, - // and just call parallel on the array! + // Use an index, access every array element by reference (because we're + // going to change each element) and just call parallel on the array! foreach(i, ref elem; parallel(arr)) { ref = sqrt(i + 1.0); } } - - ``` -- cgit v1.2.3 From 1f0b1bfb7a8d7abe3563015bad0110d6c319208f Mon Sep 17 00:00:00 2001 From: Borislav Kosharov Date: Sat, 2 Jan 2016 18:43:19 +0200 Subject: fix parallelism example typo --- d.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'd.html.markdown') diff --git a/d.html.markdown b/d.html.markdown index 6f88cf84..edb3bff5 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -254,7 +254,7 @@ void main() { // Use an index, access every array element by reference (because we're // going to change each element) and just call parallel on the array! foreach(i, ref elem; parallel(arr)) { - ref = sqrt(i + 1.0); + elem = sqrt(i + 1.0); } } ``` -- cgit v1.2.3