forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.dd
477 lines (432 loc) · 14.8 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
Ddoc
$(D_S D Programming Language,
$(SECTION1 ,
$(DIVC intro, $(DIV, $(DIV,
$(DIV,
$(TC p, pitch, $(B D) is a systems programming language with C-like
syntax and static typing. It combines efficiency, control and modeling
power with safety and programmer productivity.)
$(DIVC download,
$(DIVC btn-group-vertical,
<a href="download.html" class="btn">Downloads</a>
$(SPANC smallprint, Latest version: $(LATEST)
– $(LINK2 changelog/$(LATEST).html, Changelog))
)
)
)
$(DIVID your-code-here,
$(DIVC tip,
$(LINK2 https://forum.dlang.org/newpost/general?subject=%5Byour+code+here%5D, your code here)
$(DIV,
$(P Got a brief example illustrating D?)
$(P Submit your code to the digitalmars.D forum specifying
"[your code here]" in the subject.)
$(P Upon approval it will be showcased here on a random schedule.)
)
)
$(DIVID your-code-here-default,
----
// 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.
stdin
.byLine
.map!(l => l.replaceAll!(c => c.hit.round)
(reFloatingPoint))
.each!writeln;
}
----
)
$(EXTRA_EXAMPLE
----
// Sort lines
import std.stdio, std.array, std.algorithm;
void main()
{
stdin
.byLineCopy
.array
.sort!((a, b) => a > b) // descending order
.each!writeln;
}
----
)
)
)))
$(DIVC more,
$(DIVID news,
$(DIVID forum-summary,
<iframe src="https://forum.dlang.org/frame-announcements"></iframe>
<iframe src="https://forum.dlang.org/frame-discussions"></iframe>
)
$(DIVID twitter,
<a class="twitter-timeline" href="https://twitter.com/hashtag/dlang" data-widget-id="684452777939058688">#dlang Tweets</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
)
)
$(DIVC boxes,
$(DIVC row,
$(TOUR newspaper-o, News,
$(P $(LINK2 http://dconf.org/2017/index.html, DConf 2017)
has successfully concluded!
)
$(P
Whether you were with us in Berlin or watching from
home, we thank everyone for participating. You can
review the conference through $(LINK2
http://youtube.com/playlist?list=PL3jwVPmk_PRxo23yyoc0Ip_cP3-rCm7eB,
this YouTube playlist).
)
$(P Stay updated with
$(LINK2 http://arsdnet.net/this-week-in-d,
<cite>This Week in D</cite>) -
$(SPANC twid)
)
)
$(TOUR graduation-cap, Learn,
$(P Take the $(LINK2 https://tour.dlang.org,
Tour), explore
$(LINK2 $(ROOT_DIR)overview.html, major features) in D,
quick start with $(LINK2 $(ROOT_DIR)ctod.html, C) or
$(LINK2 $(ROOT_DIR)cpptod.html, C++) background,
setup your $(LINK2 https://wiki.dlang.org/IDEs, IDE) or
$(LINK2 https://wiki.dlang.org/Editors, editor),
and ask questions in the
$(LINK2 https://forum.dlang.org/group/digitalmars.D.learn,
Learn forum).
)
$(P For a deeper dive into D
check out $(LINK2 https://wiki.dlang.org/Books, books) about D,
among others Ali Çehreli's
$(LINK2 http://ddili.org/ders/d.en/index.html,
<cite>Programming in D</cite>).
)
)
)
$(DIVC row,
$(TOUR comments, Community,
$(P Discuss D on the $(LINK2 https://forum.dlang.org/, forums), join
the $(LINK2 irc://irc.freenode.net/d, IRC channel), read our
$(LINK2 https://dlang.org/blog, official Blog), or follow us
on $(LINK2 https://twitter.com/D_Programming, Twitter).
Browse the $(LINK2 https://wiki.dlang.org/, wiki) where among
other things you can find the
$(LINK2 https://wiki.dlang.org/Vision/2017H1, high-level vision)
of the $(LINK2 $(ROOT_DIR)foundation.html, D foundation).
)
)
$(TOUR book, Documentation,
$(P Refer to the documentation for the
$(LINK2 $(ROOT_DIR)spec/spec.html, language) and for
$(LINK2 $(ROOT_DIR)phobos/index.html, phobos), D's standard
library. The
$(LINK2 $(ROOT_DIR)dmd-windows.html, DMD manual) tells you how
to use the compiler. Read
$(LINK2 $(ROOT_DIR)articles.html, various articles) to deepen
your understanding.
)
)
)
$(DIVC row,
$(TOUR code-fork, Contribute,
$(P Report any bugs you find to our $(LINK2 $(ROOT_DIR)bugstats.php,
bug tracker). If you can fix an issue, make a pull request on
$(LINK2 https://github.com/dlang, GitHub).)
)
$(TOUR cubes, Packages,
$(P DUB is the package manager for D.
$(LINK2 https://code.dlang.org/getting_started,
Get started with DUB), and check out the
$(LINK2 https://code.dlang.org/, available packages).
)
)
)
)
$(DIVC whyd, $(SECTION2 Why D?,
$(DIVC section,
$(DIV, $(SECTION3 $(WHY_D_ICON magic) Convenience,
$(P D allows writing large code fragments without redundantly specifying types,
like dynamic languages do. On the other hand, static inference deduces types and other
code properties, giving the best of both the static and the
dynamic worlds. $(EXAMPLE 1,
----
void main()
{
// Define an array of numbers, double[].
// Compiler recognizes the common
// type of all initializers.
auto arr = [ 1, 2, 3.14, 5.1, 6 ];
// Dictionary that maps string to int,
// type is spelled int[string]
auto dictionary = [ "one" : 1, "two" : 2,
"three" : 3 ];
// Calls the min function defined below
auto x = min(arr[0], dictionary["two"]);
}
// Type deduction works for function results.
// This is important for generic functions,
// such as min below, which works correctly
// for all comparable types.
auto min(T1, T2)(T1 lhs, T2 rhs)
{
return rhs < lhs ? rhs : lhs;
}
----
))
$(P Automatic memory management makes for safe, simple, and robust code.
D also supports scoped resource management (aka the
$(HTTPS en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization, RAII) idiom)
and $(LINK2 spec/statement.html#ScopeGuardStatement, $(D scope) statements) for
deterministic transactional code that is easy to write and read. $(EXAMPLE 2,
----
import std.stdio;
class Widget { }
void main()
{
// Automatically managed.
auto w = new Widget;
// Code is executed in any case upon scope exit.
scope(exit) { writeln("Exiting main."); }
// File is closed deterministically at scope's end.
foreach (line; File("text.txt").byLine())
{
writeln(line);
}
writeln();
}
----
)
)
$(P Built-in linear and associative arrays, slices, and ranges make daily
programming simple and pleasant for tasks, both small and large. $(EXAMPLE 3,
----
#!/usr/bin/env rdmd
import std.range, std.stdio;
// Compute average line length for stdin
void main()
{
ulong lines = 0, sumLength = 0;
foreach (line; stdin.byLine())
{
++lines;
sumLength += line.length;
}
writeln("Average line length: ",
lines ? cast(double) sumLength / lines : 0.0);
}
----
))
)))
$(DIVC section, $(DIV, $(SECTION3 $(WHY_D_ICON rocket) Power,
$(P The best paradigm is to not impose something at the expense of others.
D offers classic polymorphism, value semantics, functional
style, generics, generative programming, contract programming,
and more—all harmoniously integrated. $(EXAMPLE 4,
----
// Interfaces and classes
interface Printable
{
void print(uint level)
// contract is part of the interface
in { assert(level > 0); }
}
// Interface implementation
class Widget : Printable
{
void print(uint level)
in{ }
body{ }
}
// Single inheritance of state
class ExtendedWidget : Widget
{
override void print(uint level)
in { /* weakening precondition is okay */ }
body
{
//... level may be 0 here ...
}
}
// Immutable data shared across threads
immutable string programName = "demo";
// Mutable data is thread-local
int perThread = 42;
// Explicitly shared data
shared int perApp = 5;
// Structs have value semantics
struct BigNum
{
// intercept copying
this(this) { }
// intercept destructor
~this() { }
}
void main()
{
// ...
}
----
))
$(P D offers an innovative approach to concurrency, featuring true
immutable data, message passing, no sharing by default, and
controlled mutable sharing across threads. $(HTTP
informit.com/articles/article.aspx?p=1609144, Read more).)
$(P From simple scripts to large projects, D has the breadth
to scale with any application's needs: unit testing,
information hiding, refined modularity, fast compilation, precise
interfaces. $(HTTP drdobbs.com/high-performance-computing/217801225,
Read more).)
)))
$(DIVC section, $(DIV, $(SECTION3 $(WHY_D_ICON bolt) Efficiency,
$(P D compiles naturally to efficient native code.)
$(P D is designed such that most "obvious" code is fast $(I and)
safe. On occasion a function might need to escape the confines of type
safety for ultimate speed and control. For such rare cases D offers
native pointers, type casts, access to any C function without any
intervening translation, manual memory management, custom allocators
and even inline assembly code. $(EXAMPLE 5,
----
import core.stdc.stdlib;
void livingDangerously()
{
// Access to C's malloc and free primitives
auto buf = malloc(1024 * 1024);
// free automatically upon scope exit
scope(exit) free(buf);
// Interprets memory as an array of floats
auto floats = cast(float[]) buf[0 .. 1024 * 1024];
// Even stack allocation is possible
auto moreBuf = alloca(4096 * 100);
//...
}
// Using inline asm for extra speed on x86
uint checked_multiply(uint x, uint y)
{
uint result;
version (D_InlineAsm_X86)
{
// Inline assembler "sees" D variables.
asm
{
mov EAX,x ;
mul EAX,y ;
mov result,EAX ;
jc Loverflow ;
}
return result;
}
else
{
result = x * y;
if (!y || x <= uint.max / y)
return result;
}
Loverflow:
throw new Exception("multiply overflow");
}
void main()
{
// ...
}
----
))
$(P The $(D @safe), $(D @trusted), and $(D @system) function
attributes allow the programmer to best decide the safety-efficiency
tradeoffs of an application, and have the compiler check for
consistency. $(LINK2 spec/memory-safe-d.html, Read more).)
)))
$(DIVC section, $(DIV, $(SECTION3 $(WHY_D_ICON industry) Industry-proven,
$(DIVC frontpage-orgs center,
$(FRONTPAGE_ORG Facebook, https://www.facebook.com, facebook.svg,
Online social networking service
)
$(FRONTPAGE_ORG eBay, https://www.ebay.com, ebay.jpg,
One of the world’s largest marketplaces
)
$(FRONTPAGE_ORG Sociomantic, https://www.sociomantic.com, sociomantic.png,
Real-time personalized advertising
)
$(FRONTPAGE_ORG Remedy Games, http://www.remedygames.com, remedy.png,
Triple-A game development
)
)
<div id="frontpage-orgs-more">
<i class="fa fa-angle-double-right" aria-hidden="true"></i>
$(LINK2 $(ROOT_DIR)areas-of-d-usage.html, Current D use)
$(BR)
<i class="fa fa-angle-double-right" aria-hidden="true"></i>
$(LINK2 $(ROOT_DIR)orgs-using-d.html, More organizations using D)
</div>
)))
)) $(COMMENT SECTION2 Why D?, DIVC whyd)
) $(COMMENT more)
) $(COMMENT SECTION1)
) $(COMMENT D_S)
Macros:
TITLE=Home
TAG=<$1>$+</$1>
TAG2=<$1 $2>$3</$1>
D=<span class="d_inlinecode">$0</span>
EXAMPLE=$(TAG2 a, id="a$1-control" class="example-control", )$(TAG2 div, id="a$1" class="example-box", $2)
EXTRA_EXAMPLE=<div class="your-code-here-extra" style="display:none">$0</div>
LAYOUT_PREFIX=
LAYOUT_SUFFIX=
$(SCRIPTLOAD $(ROOT_DIR)js/platform-downloads.js, data-latest="$(LATEST)")
$(SCRIPTLOAD $(ROOT_DIR)js/run-main-website.js)
$(SCRIPTLOAD //arsdnet.net/this-week-in-d/twid-latest.js)
LAYOUT_TITLE=
TOUR=$(DIVC item, $(SECTION4 $(LINK2 $1, $(TC i, fa fa-$2 big-icon)$3), $4))
TOUR=$(DIVC item, $(SECTION4 $(TC i, fa fa-$1 big-icon)$2, $3))
WHY_D_ICON=$(TC i, fa fa-$1 why-d-icon)
_=
FRONTPAGE_ORG_IMG=$(DIVC frontpage-orgs-img-wrapper vcontainer-box, <img class="vcontainer-element" src="$(ROOT_DIR)images/orgs-using-d/$0" />)
FRONTPAGE_ORG=$(DIVC frontpage-orgs-cell dont-highlight-link donthyphenate, $(LINK2 $2, $(FRONTPAGE_ORG_IMG $3)) $(H3 $1) $(P $(I $4 )))
_= Single word inline CSS needs to be escaped _=
C_A=$1:$2;
META_DESCRIPTION=D is a systems programming language with C-like syntax and static typing.
EXTRA_HEADERS=$(T style,
.why-d-icon {
padding-right: 0.2em;
}
.frontpage-orgs h3 {
$(C_A margin, 0.4em)
margin-left: 0;
margin-right: 0;
text-align: center;
}
.frontpage-orgs-img-wrapper {
$(C_A width, 175px)
$(C_A height, 75px)
padding-bottom: 10px;
text-align: center;
}
.frontpage-orgs img {
max-width: 150px;
max-height: 75px;
}
.frontpage-orgs-cell {
$(C_A width, 175px)
$(C_A display, inline-block)
vertical-align: top;
margin-bottom: 0.5em;
padding-right: 15px;
}
#frontpage-orgs-more {
text-align: right;
padding-right: 0.7em;
margin-bottom: -0.5em;
}
)
$(COMMENT index.html only for now, until we can figure out
how to generate a URL to the current page for og:url)
<meta property="og:title" content="$(FULL_TITLE)" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://dlang.org/" />
<meta property="og:image" content="https://dlang.org/images/dlogo_opengraph.png" />
<meta property="og:description" content="$(META_DESCRIPTION)" />