forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.dd
209 lines (178 loc) · 6.62 KB
/
index.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
Ddoc
$(D_S D Programming Language,
$(COMMENT $(AMAZONLINK 0321635361, <img style="float:right;
padding-left:1.5em; padding-bottom:1.5em; border-width: 0;"
src="images/tdpl.jpg" alt="The D Programming Language book" />))
$(P The K&R of D is here! Get $(AMAZONLINK 0321635361, The D
Programming Language) by Andrei Alexandrescu—the authoritative
source on everything D. From the book's introduction:
$(BLOCKQUOTE $(AMAZONLINK 0321635361, The D Programming Language) by
Andrei Alexandrescu, D is a language that attempts to consistently do
the right thing within the constraints it chose: system-level access
to computing resources, high performance, and syntactic similarity
with C-derived languages. In trying to do the right thing, D
sometimes stays with tradition and does what other languages do, and
other times it breaks tradition with a fresh, innovative solution. On
occasion that meant revisiting the very constraints that D ostensibly
embraced. For example, large program fragments or indeed entire
programs can be written in a well-defined memory-safe subset of D,
which entails giving away a small amount of system-level access for a
large gain in program debuggability.))
$(P D is a multi-paradigm programming language that combines a
principled approach with a focus on practicality. In D you get to
harness the power and high performance of C and C++ and also the
safety and programmer productivity of modern languages such as Ruby
and Python. Special attention is given to the needs of quality
assurance, documentation, portability, and reliability.)
$(P The D language is statically typed and compiles directly to machine code.
It’s multiparadigm, supporting many programming styles:
imperative, object oriented, and metaprogramming. It’s a member of the C
syntax family, and its appearance is very similar to that of C++.
Here’s a quick list of $(LINK2 comparison.html, features).
)
$(P This site does not refer to the first edition of the language,
known as "D version 1" or "D1". Currently, D1 is in maintenance mode
and has documentation available $(LINK2
http://www.digitalmars.com/d/1.0/index.html,here). We recommend the
current edition of the D programming language (formerly known as "D2")
for new projects. )
$(P There are currently three implementations:
$(OL
$(LI Digital Mars dmd for
$(LINK2 http://www.digitalmars.com/d/2.0/dmd-windows.html,
Windows),
$(LINK2 http://www.digitalmars.com/d/2.0/dmd-linux.html, x86 Linux),
$(LINK2 http://www.digitalmars.com/d/2.0/dmd-osx.html, Mac OS X), and
$(LINK2 http://www.digitalmars.com/d/2.0/dmd-freebsd.html, x86 FreeBSD).
)
$(LI LLVM D Compiler $(LINK2 http://www.dsource.org/projects/ldc, ldc).
)
$(COMMENT
$(LI Gnu D compiler $(LINK2 http://dgcc.sourceforge.net/, gdc)
for several platforms, including
$(LINK2 http://gdcwin.sourceforge.net/, Windows) and
$(LINK2 http://gdcmac.sourceforge.net/, Mac OS X)
for D versions 1.030 and 2.014.
)
)
$(LI Gnu D compiler $(LINK2 http://bitbucket.org/goshawk/gdc/wiki/Home, gdc).
)
$(COMMENT $(LINK2 http://dnet.codeplex.com/, D.NET compiler)
alpha for .NET for D version 2.)
)
)
$(P A large and growing collection of D source code and projects
are at $(LINK2 http://www.dsource.org, dsource).
More links to innumerable D wikis, libraries, tools, media articles,
etc. are at $(LINK2 http://www.digitalmars.com/d/dlinks.html, dlinks).
)
$(COMMENT $(P
This document is available as a
$(LINK2 http://www.prowiki.org/wiki4d/wiki.cgi?LanguageSpecification/PDFArchive, pdf),
as well as in
$(LINK2 http://www.kmonos.net/alang/d/, Japanese)
and
$(LINK2 http://elderane.50webs.com/tuto/d/, Portugese)
translations.
A German book
$(LINK2 http://www.amazon.de/Programmieren-D-Einf%C3%BChrung-neue-Programmiersprache/dp/3939084697/, Programming in D: Introduction to the new Programming Language)
is available, as well as
a Japanese book
$(LINK2 http://www.gihyo.co.jp/books/syoseki-contents.php/4-7741-2208-4, D Language Perfect Guide),
and a Turkish book
$(LINK2 http://ddili.org/ders/d/, D Programlama Dili Dersleri).
))
$(COMMENT: Japanese by Kazuhiro Inaba, Portugese by Christian Hartung)
$(P This is an example D program illustrating some of the capabilities:)
----
#!/usr/bin/rdmd
/* shebang is supported */
/* Hello World in D
To compile:
dmd hello.d (or on Unix just make hello.d executable and run it)
or to optimize:
dmd -O -inline -release hello.d
*/
import std.stdio;
void main(string[] args)
{
$(V1 writefln("Hello World, Reloaded");)$(V2 writeln("Hello World, Reloaded");)
// auto type inference and built-in foreach
foreach (argc, argv; args)
{
// Object Oriented Programming
auto cl = new CmdLin(argc, argv);
// Improved typesafe printf
writeln(cl.argnum, cl.suffix, " arg: ", cl.argv);
// Automatic or explicit memory management
delete cl;
}
// Nested structs and classes
struct specs
{
// all members automatically initialized
size_t count, allocated;
}
// Nested functions can refer to outer
// variables like args
specs argspecs()
{
specs* s = new specs;
// no need for '->'
s.count = args.length; // get length of array with .length
s.allocated = typeof(args).sizeof; // built-in native type properties
foreach (argv; args)
s.allocated += argv.length * typeof(argv[0]).sizeof;
return *s;
}
// built-in string and common string operations
writefln("argc = %d, " ~ "allocated = %d",
argspecs().count, argspecs().allocated);
}
class CmdLin
{
private size_t _argc;
private string _argv;
public:
this(size_t argc, string argv) // constructor
{
_argc = argc;
_argv = argv;
}
size_t argnum()
{
return _argc + 1;
}
string argv()
{
return _argv;
}
string suffix()
{
string suffix = "th";
switch (_argc)
{
case 0:
suffix = "st";
break;
case 1:
suffix = "nd";
break;
case 2:
suffix = "rd";
break;
default:
break;
}
return suffix;
}
}
----
$(P $(B Notice:) We welcome feedback about the D compiler or language, but please be explicit about
any claims to intellectual property rights with a copyright or patent notice if you have such for
your contributions. We want D to remain open and free to use, and do not wish to be caught by
someone posting a patch to the compiler, and then later claim compensation for that work.)
)
Macros:
TITLE=Intro
WIKI=Intro