Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Apr 23, 2015
1 parent 7e664d4 commit 95416aa
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
*.sublime-workspace

*.sublime-project

*.o

examples/readdoubles2

examples/readdoubles1
20 changes: 18 additions & 2 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
Introduction
================

It was mentioned that students can quickly master the D programming language without a detailed study using mostly its subset, which is close to the C PL.
It was mentioned that students can quickly master the D programming language without a detailed study using mostly its subset, which is close to the C PL.

Рассмотрим простую программу, которая считывает из файла 10 строк, содержащих по одному числу и
печатает в стандартный выход эти же числа, но сдвинутые на математическое ожидание.

Тогда как идиоматический D код выглядет достаточно непревычно:

.. literalinclude:: ../../examples/readdoubles2.d
:language: d
:tab-width: 4

для многих незнакомых с языком D та же самая программа может быть реализована хоть и более грамоздким,
но в тоже время более понятным способом:

.. literalinclude:: ../../examples/readdoubles1.d
:language: d
:tab-width: 4

The present documentation is submitted to the rapid introduction to D for those who are already somehow familiar with the C language, and for those who for some reasons do not want to waste time on a consistent study of the language and related tools.

If you decide to use the D language and related tools in your daily work, you should start immediately with the study of the `official page <http://dlang.org>`_ and of the book `"The D Programming Language" <http://erdani.com/index.php/books/tdpl/>`_ by Andrei Alexandrescu.
If you decide to use the D language in your daily work, you should start immediately with the study of the `official page <http://dlang.org>`_ and of the book `"The D Programming Language" <http://erdani.com/index.php/books/tdpl/>`_ by Andrei Alexandrescu.

Probably D is the most powerful of the present `system programming languages <http://en.wikipedia.org/wiki/System_programming_language>`_.
`It is a dragon <http://thebird.nl/blog/D_Dragon.html>`_. Have a nice flight!
10 changes: 10 additions & 0 deletions examples/10numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
12.234
234.12
3.2134
-123.432
2.454
324.234
0.
2345.
2
2.43
9 changes: 9 additions & 0 deletions examples/matplotlib/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "atmosphere_gm_charts",
"dependencies": {
"pyd": "~>0.9.4",
},
"subConfigurations": {
"pyd": "python34",
},
}
5 changes: 5 additions & 0 deletions examples/matplotlib/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import std.stdio;

void main() {

}
22 changes: 22 additions & 0 deletions examples/readdoubles1.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import std.stdio;

void main()
{
File fin = File("10numbers.txt");
double[] sample;
sample.length = 10;
double mean = 0;
for(int i = 0; i < sample.length; i++)
{
fin.readf("%s", &sample[i]);
if(!fin.eof)
fin.readln();
mean += sample[i];
}
mean /= sample.length;
// prints one element per line
for(int i = 0; i < sample.length; i++)
{
writeln(sample[i] - mean);
}
}
19 changes: 19 additions & 0 deletions examples/readdoubles2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import std.algorithm.iteration : map, each;
import std.array : array;
import std.conv : to;
import std.range : takeExactly, tee;
import std.stdio;

void main()
{
double mean = 0;
auto sample = File("10numbers.txt")
.byLine
.takeExactly(10)
.map!(to!double)
.tee!((x){mean += x;})
.array;
mean /= sample.length;
// prints one element per line
sample.map!(x => x - mean).each!writeln;
}

0 comments on commit 95416aa

Please sign in to comment.