Programming in D Ali Çehreli 2024 scribd download
Programming in D Ali Çehreli 2024 scribd download
com
https://ebookmeta.com/product/programming-in-d-ali-cehreli/
OR CLICK HERE
DOWLOAD NOW
Ali Çehreli
D version: 2.098.1
1
Book revision: 2022-02-21
2
The most recent electronic versions of this book are available online .
3
Edited by Luís Marques
4
Cover design by İzgi Yapıcı
5
Cover illustration by Sarah Reece
6
Published by Ali Çehreli
Fonts:
Andada by Carolina Giovagnoli for Huerta Tipográfica
Open Sans by Steve Matteson
DejaVu Mono by DejaVu Fonts
ISBNs:
978-0-692-59943-3 hardcover by IngramSpark
978-0-692-52957-7 paperback by IngramSpark
978-1-515-07460-1 paperback by Kindle Direct Publishing
978-1-519-95441-1 ePUB by Draft2Digital
1. https://bitbucket.org/acehreli/ddili
2. http://ddili.org/ders/d.en
3. http://www.luismarques.eu
4. http://izgiyapici.com
5. mailto:sarah@reeceweb.com
6. mailto:acehreli@yahoo.com
Contents
Foreword by Andrei Alexandrescu xix
Preface xxi
Acknowledgments ............................................................................................................. xxi
1. The Hello World Program 1
Compiler installation ............................................................................................................1
Source file...................................................................................................................................1
Compiling the hello world program ...............................................................................1
Compiler switches ................................................................................................................. 2
IDE................................................................................................................................................ 3
Contents of the hello world program ............................................................................ 3
Exercises .................................................................................................................................... 4
2. writeln and write 5
Exercises .................................................................................................................................... 5
3. Compilation 6
Machine code .......................................................................................................................... 6
Programming language....................................................................................................... 6
Interpreter ................................................................................................................................ 6
Compiler .................................................................................................................................... 7
4. Fundamental Types 8
Logical expression type ....................................................................................................... 8
Integer types ............................................................................................................................ 8
Floating point types .............................................................................................................. 8
Character types....................................................................................................................... 9
Properties of types................................................................................................................. 9
size_t ......................................................................................................................................10
Exercise ....................................................................................................................................10
5. Assignment and Order of Evaluation 11
The assignment operation ................................................................................................11
Order of evaluation..............................................................................................................11
Exercise .....................................................................................................................................11
6. Variables 12
Exercise .................................................................................................................................... 13
7. Standard Input and Output Streams 14
Exercise .................................................................................................................................... 14
8. Reading from the Standard Input 15
Skipping the whitespace characters ............................................................................ 16
Additional information ..................................................................................................... 17
Exercise .................................................................................................................................... 17
9. Logical Expressions 18
Logical Expressions............................................................................................................. 18
Grouping expressions ........................................................................................................ 21
Reading bool input ............................................................................................................. 21
Exercises .................................................................................................................................. 21
10. if Statement 24
The if block and its scope ...............................................................................................24
The else block and its scope ..........................................................................................24
Always use the scope curly brackets............................................................................25
The "if, else if, else" chain..................................................................................................25
v
Exercises ..................................................................................................................................27
11. while Loop 28
The continue statement ..................................................................................................28
The break statement ..........................................................................................................29
Unconditional loop .............................................................................................................29
Exercises ..................................................................................................................................30
12. Integers and Arithmetic Operations 31
Exercises .................................................................................................................................. 41
13. Floating Point Types 42
Floating point type properties........................................................................................42
.nan ...........................................................................................................................................43
Specifying floating point values ....................................................................................43
Overflow is not ignored.....................................................................................................45
Precision ..................................................................................................................................45
There is no truncation in division ................................................................................45
Which type to use ................................................................................................................46
Cannot represent all values.............................................................................................46
Unorderedness......................................................................................................................47
Exercises ..................................................................................................................................48
14. Arrays 49
Definition ................................................................................................................................49
Containers and elements..................................................................................................50
Accessing the elements......................................................................................................50
Index ..........................................................................................................................................51
Fixed-length arrays vs. dynamic arrays ......................................................................51
Using .length to get or set the number of elements ............................................51
An array example ................................................................................................................52
Initializing the elements...................................................................................................52
Basic array operations ....................................................................................................... 53
Exercises .................................................................................................................................. 55
15. Characters 57
History...................................................................................................................................... 57
Unicode encodings..............................................................................................................58
The character types of D ...................................................................................................59
Character literals .................................................................................................................59
Control characters.............................................................................................................. 60
Single quote and backslash ............................................................................................ 60
The std.uni module ............................................................................................................. 61
Limited support for ı and i ...............................................................................................62
Problems with reading characters ...............................................................................62
D's Unicode support............................................................................................................63
Summary.................................................................................................................................64
16. Slices and Other Array Features 65
Slices..........................................................................................................................................65
Using $, instead of array.length ................................................................................66
Using .dup to copy ..............................................................................................................66
Assignment.............................................................................................................................67
Making a slice longer may terminate sharing.........................................................67
Operations on all elements............................................................................................. 70
Multi-dimensional arrays ................................................................................................72
Summary.................................................................................................................................74
vi
Exercise ....................................................................................................................................74
17. Strings 75
readln and strip, instead of readf ........................................................................... 75
formattedRead for parsing strings .............................................................................76
Double quotes, not single quotes...................................................................................77
string, wstring, and dstring are immutable......................................................77
Potentially confusing length of strings.......................................................................78
String literals .........................................................................................................................79
String concatenation..........................................................................................................79
Comparing strings.............................................................................................................. 80
Lowercase and uppercase are different..................................................................... 80
Exercises .................................................................................................................................. 81
18. Redirecting the Standard Input and Output Streams 82
Redirecting the standard output to a file with operator > ..................................82
Redirecting the standard input from a file with operator < ..............................82
Redirecting both standard streams..............................................................................83
Piping programs with operator | ..................................................................................83
Exercise ....................................................................................................................................83
19. Files 84
Fundamental concepts ......................................................................................................84
std.stdio.File struct.....................................................................................................86
Exercise ....................................................................................................................................87
20. auto and typeof 88
auto ...........................................................................................................................................88
typeof ......................................................................................................................................88
Exercise ....................................................................................................................................89
21. Name Scope 90
Defining names closest to their first use................................................................... 90
22. for Loop 93
The sections of the while loop.......................................................................................93
The sections of the for loop ............................................................................................93
The sections may be empty .............................................................................................94
The name scope of the loop variable ...........................................................................94
Exercises ..................................................................................................................................95
23. Ternary Operator ?: 96
The type of the ternary expression ..............................................................................97
Exercise ....................................................................................................................................98
24. Literals 99
Integer literals.......................................................................................................................99
Floating point literals....................................................................................................... 101
Character literals ............................................................................................................... 101
String literals .......................................................................................................................102
Literals are calculated at compile time.....................................................................103
Exercises ................................................................................................................................103
25. Formatted Output 104
format_character .................................................................................................................105
width........................................................................................................................................107
separator .................................................................................................................................107
precision..................................................................................................................................108
flags ..........................................................................................................................................108
vii
Positional parameters ......................................................................................................109
Formatted element output ............................................................................................. 110
format ..................................................................................................................................... 111
Exercises ................................................................................................................................ 112
26. Formatted Input 113
Format specifier characters........................................................................................... 114
Exercise .................................................................................................................................. 114
27. do-while Loop 115
Exercise .................................................................................................................................. 116
28. Associative Arrays 117
Definition .............................................................................................................................. 117
Adding key-value pairs .................................................................................................... 118
Initialization ........................................................................................................................ 118
Removing key-value pairs .............................................................................................. 118
Determining the presence of a key............................................................................. 119
Properties .............................................................................................................................. 119
Example .................................................................................................................................120
Exercises ................................................................................................................................120
29. foreach Loop 121
The foreach syntax.......................................................................................................... 121
continue and break ........................................................................................................122
foreach with arrays.........................................................................................................122
foreach with strings and std.range.stride .....................................................122
foreach with associative arrays ................................................................................. 123
foreach with number ranges ...................................................................................... 123
foreach with structs, classes, and ranges............................................................... 123
The counter is automatic only for arrays................................................................124
The copy of the element, not the element itself ....................................................124
The integrity of the container must be preserved ............................................... 125
foreach_reverse to iterate in the reverse direction......................................... 125
Exercise ..................................................................................................................................126
30. switch and case 127
The goto statement...........................................................................................................127
The expression must be an integer, string, or bool type ..................................129
Value ranges.........................................................................................................................129
Distinct values.....................................................................................................................130
The final switch statement ......................................................................................130
When to use..........................................................................................................................130
Exercises .................................................................................................................................131
31. enum 132
Effects of magic constants on code quality............................................................. 132
The enum syntax ................................................................................................................. 132
Actual values and base types ........................................................................................ 133
enum values that are not of an enum type................................................................. 133
Properties .............................................................................................................................. 134
Converting from the base type..................................................................................... 135
Exercise .................................................................................................................................. 135
32. Functions 136
Parameters............................................................................................................................ 137
Calling a function .............................................................................................................. 139
viii
Doing work ........................................................................................................................... 139
The return value................................................................................................................. 139
The return statement .................................................................................................... 140
void functions ................................................................................................................... 140
The name of the function............................................................................................... 141
Code quality through functions................................................................................... 141
Exercises ................................................................................................................................ 145
33. Immutability 147
Immutable variables ........................................................................................................148
Parameters............................................................................................................................150
Initialization ........................................................................................................................ 154
Immutability of the slice versus the elements....................................................... 155
How to use ............................................................................................................................ 157
Summary............................................................................................................................... 158
34. Value Types and Reference Types 159
Value types............................................................................................................................ 159
Reference variables ...........................................................................................................160
Reference types................................................................................................................... 161
Fixed-length arrays are value types, slices are reference types...................... 165
Experiment........................................................................................................................... 165
Summary...............................................................................................................................167
35. Function Parameters 168
Parameters are always copied ......................................................................................168
Referenced variables are not copied..........................................................................169
Parameter qualifiers ......................................................................................................... 171
Summary...............................................................................................................................179
Exercise ..................................................................................................................................180
36. Lvalues and Rvalues 181
Limitations of rvalues...................................................................................................... 181
Using auto ref parameters to accept both lvalues and rvalues ..................182
Terminology......................................................................................................................... 183
37. Lazy Operators 184
38. Program Environment 185
The return value of main() ........................................................................................... 185
Standard error stream stderr .....................................................................................187
Parameters of main() ......................................................................................................187
Command line options and the std.getopt module ........................................188
Environment variables....................................................................................................190
Starting other programs .................................................................................................190
Summary............................................................................................................................... 191
Exercises ................................................................................................................................ 191
39. Exceptions 192
The throw statement to throw exceptions ..............................................................192
The try-catch statement to catch exceptions .....................................................197
Exception properties .......................................................................................................202
Kinds of errors ................................................................................................................... 203
Summary.............................................................................................................................. 205
40. scope 206
41. assert and enforce 208
Syntax....................................................................................................................................208
ix
static assert .................................................................................................................209
assert even if absolutely true........................................................................................210
No value nor side effect...................................................................................................210
Disabling assert checks ................................................................................................ 211
enforce for throwing exceptions ............................................................................... 211
How to use ............................................................................................................................ 211
Exercises ................................................................................................................................212
42. Unit Testing 214
Causes of bugs .....................................................................................................................214
Discovering the bugs ........................................................................................................214
Unit testing for catching bugs ...................................................................................... 215
Activating the unit tests ..................................................................................................216
unittest blocks.................................................................................................................216
Testing for exceptions ......................................................................................................217
Test driven development.................................................................................................218
Exercise .................................................................................................................................220
43. Contract Programming 221
in blocks for preconditions...........................................................................................221
out blocks for postconditions ..................................................................................... 222
Expression-based contracts.......................................................................................... 224
Disabling contract programming .............................................................................. 224
in blocks versus enforce checks............................................................................... 224
Exercise ................................................................................................................................. 226
44. Lifetimes and Fundamental Operations 228
Lifetime of a variable....................................................................................................... 228
Lifetime of a parameter.................................................................................................. 228
Fundamental operations ............................................................................................... 229
45. The null Value and the is Operator 233
The null value ....................................................................................................................233
The is operator ................................................................................................................. 234
The !is operator............................................................................................................... 234
Assigning the null value............................................................................................... 234
Summary...............................................................................................................................235
46. Type Conversions 237
Automatic type conversions..........................................................................................237
Explicit type conversions............................................................................................... 242
Summary.............................................................................................................................. 245
47. Structs 246
Definition ............................................................................................................................. 246
Accessing the members .................................................................................................. 248
Construction ....................................................................................................................... 249
Copying and assignment ................................................................................................ 251
Struct literals .......................................................................................................................253
static members................................................................................................................253
Exercises ............................................................................................................................... 256
48. Variable Number of Parameters 258
Default arguments ........................................................................................................... 258
Variadic functions ............................................................................................................260
Exercise ................................................................................................................................. 263
x
49. Function Overloading 265
Overload resolution ......................................................................................................... 266
Function overloading for user-defined types........................................................ 266
Limitations .......................................................................................................................... 267
Exercise ................................................................................................................................. 268
50. Member Functions 269
Defining member functions ......................................................................................... 269
Exercises ................................................................................................................................273
51. const ref Parameters and const Member Functions 275
immutable objects .............................................................................................................275
ref parameters that are not const ............................................................................275
const ref parameters....................................................................................................275
Non-const member functions .................................................................................... 276
const member functions ............................................................................................. 276
inout member functions .............................................................................................. 277
How to use ........................................................................................................................... 278
52. Constructor and Other Special Functions 279
Constructor ......................................................................................................................... 279
Destructor ............................................................................................................................ 288
Copy constructor...............................................................................................................290
Postblit................................................................................................................................... 292
Assignment operator....................................................................................................... 293
Disabling member functions ....................................................................................... 295
Summary.............................................................................................................................. 297
53. Operator Overloading 298
Overloadable operators..................................................................................................300
Element indexing and slicing operators ................................................................. 302
Defining more than one operator at the same time........................................... 303
Return types of operators.............................................................................................. 304
opEquals() for equality comparisons .................................................................... 306
opCmp() for sorting.......................................................................................................... 307
opCall() to call objects as functions....................................................................... 309
Indexing operators............................................................................................................310
Slicing operators ................................................................................................................ 313
opCast for type conversions ......................................................................................... 315
Catch-all operator opDispatch.................................................................................... 317
Inclusion query by opBinaryRight!"in".............................................................. 317
Exercise .................................................................................................................................. 319
54. Classes 322
Comparing with structs ................................................................................................. 322
Summary...............................................................................................................................327
55. Inheritance 328
Warning: Inherit only if "is a" ...................................................................................... 330
Inheritance from at most one class........................................................................... 330
Hierarchy charts ................................................................................................................ 331
Accessing superclass members .................................................................................... 331
Constructing superclass members .............................................................................332
Overriding the definitions of member functions.................................................333
Using the subclass in place of the superclass.........................................................334
Inheritance is transitive..................................................................................................335
xi
Abstract member functions and abstract classes.................................................336
Example .................................................................................................................................337
Summary.............................................................................................................................. 340
Exercises ............................................................................................................................... 340
56. Object 342
typeid and TypeInfo ..................................................................................................... 342
toString .............................................................................................................................. 344
opEquals .............................................................................................................................. 344
opCmp ...................................................................................................................................... 347
toHash ................................................................................................................................... 349
Exercises ................................................................................................................................ 351
57. Interfaces 354
Definition ..............................................................................................................................354
Inheriting from an interface ....................................................................................354
Inheriting from more than one interface ........................................................... 355
Inheriting from interface and class ....................................................................356
Inheriting interface from interface ...................................................................356
static member functions.............................................................................................356
final member functions ...............................................................................................358
How to use ............................................................................................................................359
Abstraction ...........................................................................................................................359
Example ................................................................................................................................ 360
Summary............................................................................................................................... 361
58. destroy and scoped 363
An example of calling destructors late .....................................................................363
destroy() to execute the destructor ....................................................................... 364
When to use......................................................................................................................... 364
Example ................................................................................................................................ 364
scoped() to call the destructor automatically .................................................... 367
Summary.............................................................................................................................. 368
59. Modules and Libraries 370
Packages................................................................................................................................. 371
Importing modules ........................................................................................................... 371
Libraries................................................................................................................................ 376
60. Encapsulation and Protection Attributes 379
Encapsulation..................................................................................................................... 380
Protection attributes ....................................................................................................... 380
Definition .............................................................................................................................. 381
Module imports are private by default ..................................................................... 381
When to use encapsulation .......................................................................................... 382
Example .................................................................................................................................383
61. Universal Function Call Syntax (UFCS) 385
62. Properties 388
Calling functions without parentheses ................................................................... 388
Property functions that return values ..................................................................... 388
Property functions that are used in assignment ................................................. 389
Properties are not absolutely necessary ................................................................. 390
When to use.......................................................................................................................... 391
63. Contract Programming for Structs and Classes 393
Preconditions and postconditions for member functions...............................393
xii
Preconditions and postconditions for object consistency .............................. 394
invariant() blocks for object consistency...........................................................395
Contract inheritance ....................................................................................................... 396
Summary.............................................................................................................................. 398
64. Templates 399
Function templates ..........................................................................................................400
More than one template parameter.......................................................................... 401
Type deduction...................................................................................................................402
Explicit type specification .............................................................................................402
Template instantiation ................................................................................................... 403
Template specializations................................................................................................ 403
Struct and class templates ............................................................................................404
Default template parameters.......................................................................................406
Every template instantiation yields a distinct type............................................407
A compile-time feature...................................................................................................407
Class template example: stack data structure ......................................................407
Function template example: binary search algorithm ..................................... 410
Summary...............................................................................................................................412
65. Pragmas 414
pragma(msg) .......................................................................................................................414
pragma(lib) .......................................................................................................................414
pragma(inline) ................................................................................................................414
pragma(startaddress).................................................................................................416
pragma(mangle) ................................................................................................................416
66. alias and with 418
alias .......................................................................................................................................418
with ........................................................................................................................................ 422
Summary.............................................................................................................................. 423
67. alias this 424
68. Pointers 425
The concept of a reference............................................................................................ 425
Syntax.................................................................................................................................... 427
Pointer value and the address-of operator & ......................................................... 428
The access operator * ...................................................................................................... 429
The . (dot) operator to access a member of the pointee................................... 429
Modifying the value of a pointer................................................................................ 430
Pointers are risky.............................................................................................................. 432
The element one past the end of an array .............................................................. 432
Using pointers with the array indexing operator [] ..........................................433
Producing a slice from a pointer ................................................................................ 434
void* can point at any type ..........................................................................................435
Using pointers in logical expressions........................................................................435
new returns a pointer for some types ....................................................................... 436
The .ptr property of arrays......................................................................................... 437
The in operator of associative arrays ...................................................................... 437
When to use pointers ...................................................................................................... 438
Examples .............................................................................................................................. 439
Exercises ............................................................................................................................... 444
69. Bit Operations 446
Representation of data at the lowest level.............................................................. 446
xiii
Binary number system ................................................................................................... 447
Hexadecimal number system...................................................................................... 448
Bit operations ..................................................................................................................... 450
Semantics............................................................................................................................. 454
Common uses ..................................................................................................................... 456
Exercises ............................................................................................................................... 458
70. Conditional Compilation 460
debug......................................................................................................................................460
version(tag) and version(level) ...................................................................... 463
Assigning identifiers to debug and version ......................................................... 464
static if............................................................................................................................ 464
static assert ................................................................................................................. 465
Type traits ............................................................................................................................ 466
Summary.............................................................................................................................. 467
71. is Expression 468
is (T) ................................................................................................................................... 468
is (T Alias) .................................................................................................................... 468
is (T : OtherT) ............................................................................................................ 469
is (T Alias : OtherT) ............................................................................................. 469
is (T == Specifier) .................................................................................................. 469
is (T identifier == Specifier) .......................................................................471
is (/* ... */ Specifier, TemplateParamList) ..................................... 472
72. Function Pointers, Delegates, and Lambdas 475
Function pointers ............................................................................................................. 475
Anonymous functions ....................................................................................................480
Delegates............................................................................................................................... 483
toString() with a delegate parameter............................................................... 487
Summary.............................................................................................................................. 489
73. foreach with Structs and Classes 491
foreach support by range member functions ......................................................491
foreach support by opApply and opApplyReverse member functions . 493
Loop counter ....................................................................................................................... 496
Warning: The collection must not mutate during the iteration ................... 498
Exercises ............................................................................................................................... 499
74. Nested Functions, Structs, and Classes 500
Summary.............................................................................................................................. 503
75. Unions 504
Anonymous unions.......................................................................................................... 505
Dissecting other members ............................................................................................ 505
Examples .............................................................................................................................. 506
76. Labels and goto 510
goto .........................................................................................................................................510
Loop labels ............................................................................................................................ 512
goto in case sections....................................................................................................... 512
Summary............................................................................................................................... 512
77. Tuples 513
Tuple and tuple() ........................................................................................................... 513
AliasSeq ............................................................................................................................... 516
.tupleof property............................................................................................................ 518
Summary............................................................................................................................... 519
xiv
78. More Templates 520
The shortcut syntax ......................................................................................................... 520
Kinds of templates.............................................................................................................522
Kinds of template parameters......................................................................................525
typeof(this), typeof(super), and typeof(return) ...................................533
Template specializations.................................................................................................534
Meta programming...........................................................................................................534
Compile-time polymorphism........................................................................................536
Code bloat..............................................................................................................................537
Template constraints........................................................................................................538
Using templates in multi-dimensional operator overloading ........................ 541
Summary.............................................................................................................................. 546
79. More Functions 547
Return type attributes..................................................................................................... 547
Behavioral attributes....................................................................................................... 550
Code safety attributes ...................................................................................................... 555
Compile time function execution (CTFE).................................................................556
Summary...............................................................................................................................558
80. Mixins 560
Template mixins................................................................................................................ 560
String mixins ...................................................................................................................... 562
Mixin name spaces........................................................................................................... 564
String mixins in operator overloading .....................................................................565
Mixed in destructors ........................................................................................................565
Importing text files........................................................................................................... 566
Example .................................................................................................................................567
81. Ranges 569
History................................................................................................................................... 569
Ranges are an integral part of D................................................................................. 570
Traditional implementations of algorithms.......................................................... 570
Phobos ranges ..................................................................................................................... 571
InputRange ..........................................................................................................................573
ForwardRange .................................................................................................................... 582
BidirectionalRange ..................................................................................................... 584
RandomAccessRange ........................................................................................................585
OutputRange ....................................................................................................................... 591
Range templates ................................................................................................................ 594
Summary.............................................................................................................................. 594
82. More Ranges 596
Range kind templates...................................................................................................... 596
ElementType and ElementEncodingType ............................................................ 599
More range templates ..................................................................................................... 599
Run-time polymorphism with inputRangeObject() and
outputRangeObject() ..................................................................................................600
Summary...............................................................................................................................601
83. static foreach 602
84. Parallelism 605
taskPool.parallel() ..................................................................................................607
Task ........................................................................................................................................608
taskPool.asyncBuf() ...................................................................................................612
xv
Another Random Document on
Scribd Without Any Related Topics
covered hill in the midst of forests. Two hundred coolies worked
forty-five days in clearing away vegetation and excavating the buried
terraces. Measurements and drawings were made, and twelve plates
from them accompany Sir Stamford Raffles’s work. After the Dutch
recovered possession of Java, their artists and archæologists gave
careful study to this monument of earlier civilization and arts. Further
excavations showed that the great platform or broad terrace around
the temple mass was of later construction than the body of the
pyramid, that a flooring nine feet deep had been put entirely around
the lower walls, presumably to brace them, and thus covering many
inscriptions the meanings of which have not yet been given, not to
English readers at least. Dutch scientists devoted many seasons to
the study of these ruins, and Herr Brumund’s scholarly text,
completed and edited by Dr. Leemans of Leyden, accompanies and
explains the great folio volumes of four hundred plates, after
Wilsen’s drawings, published by the Dutch government in 1874.
Since their uncovering the ruins have been kept free from
vegetation, but no other care has been taken. In this comparatively
short time legends have grown up, local customs have become
fixed, and Boro Boedor holds something of the importance it should
in its immediate human relations.
For more than six centuries the hill-temple was lost to sight,
covered with trees and rank vegetation; and when the Englishmen
brought the great sculptured monument to light, the gentle, easily
superstitious Javanese of the neighborhood regarded these recha—
statues and relics of the ancient, unknown cult—with the greatest
reverence. They adopted them as tutelary divinities, as it were,
indigenous to their own soil. While Wilsen lived there the people
brought daily offerings of flowers. The statue on the first circular
terrace at the right of the east staircase, and the secluded image at
the very summit, were always surrounded with heaps of stemless
flowers laid on moss and plantain-leaves. Incense was burned to
these recha, and the people daubed them with the yellow powder
with which princes formerly painted, and even humble bridegrooms
now paint, themselves on festal days, just as Burmese Buddhists
daub gold-leaf on their shrines, and, like the Cingalese Buddhists,
heap champak and tulse, jasmine, rose, and frangipani flowers,
before their altars. When questioned, the people owned that the
offerings at Boro Boedor were in fulfilment of a vow or in
thanksgiving for some event in their lives—a birth, death, marriage,
unexpected good fortune, or recovery from illness. Other worshipers
made the rounds of the circular terraces, reaching to touch each
image in its latticed bell, and many kept all-night vigils among the
dagobas of the Nirvana circles. Less appealing was the custom, that
grew up among the Chinese residents of Djokjakarta and its
neighborhood, of making the temple the goal of general pilgrimage
on the Chinese New Year’s day. They made food and incense
offerings to the images, and celebrated with fireworks, feasts, and a
general May-fair and popular outdoor fête.
“In the whole course of my life I have never met with such stupendous
and finished specimens of human labor and of the science and taste of
ages long since forgot, crowded together in so small a compass, as in this
little spot [Brambanam], which, to use a military phrase, I deem to have
been the headquarters of Hinduism in Java.” (Report to Sir Stamford
Raffles by Captain George Baker of the Bengal establishment.)
There are ruins of more than one hundred and fifty temples in the
historic region lying between Djokjakarta and Soerakarta, or Djokja
and Solo, as common usage abbreviates those syllables of
unnecessary exertion in this steaming, endless mid-summer land of
Middle Java. As the train races on the twenty miles from Djokja to
Brambanam, there is a tantalizing glimpse of the ruined temples at
Kalasan; and one small temple there, the Chandi Kali Bening, ranks
as the gem of Hindu art in Java. It is entirely covered, inside as well
as outside, with bas-reliefs and ornamental carvings which surpass
in elaboration and artistic merit everything else in this region, where
refined ornament and lavish decoration reached their limit at the
hands of the early Hindu sculptors. The Sepoy soldiers who came
with the British engineers were lost in wonder at Kalasan, where the
remains of Hindu art so far surpassed anything they knew in India
itself; while the extent and magnificence of Brambanam’s Brahmanic
and Buddhist temple ruins amaze every visitor—even after Boro
Boedor.
TEMPLE OF LORO JONGGRAN AT BRAMBANAM.
The pity of all this ruined splendor moves one strongly, and one
deplores the impossibility of reconstructing, even on paper, the
whole magnificent place of worship. The wealth of ornament makes
all other temple buildings seem plain and featureless, and one set of
bas-reliefs just rescued and set up in line, depicting scenes from the
Ramayan, would be treasure enough for an art museum. On this
long series of carved stones disconsolate Rama is shown searching
everywhere for Sita, his stolen wife, until the king of the monkeys,
espousing his cause, leads him to success. The story is wonderfully
told in stone, the chisel as eloquent as the pen, and everywhere one
reads as plainly the sacred tales and ancient records. The graceful
figures and their draperies tell of Greek influences acting upon those
northern Hindus who brought the religion to the island; and the
beautifully conventionalized trees and fruits and flowers, the mythical
animals and gaping monsters along the staircases, the masks,
arabesques, bands, scrolls, ornamental keystones, and all the
elaborate symbols and attributes of deities lavished on this group of
temples, constitute a whole gallery of Hindu art, and a complete
grammar of its ornament.
When the director was called away to his workmen, we bade our
guiding Mohammedan lead the way to Chandi Sewou, the
“Thousand Temples,” or great Buddhist shrine of the ancient capital.
“Oh,” he cried, “it is far, far from here—an hour to walk. You must go
to Chandi Sewou in a boat. The water is up to here,” touching his
waist, “and there are many, many snakes.” Distrusting, we made him
lead on in the direction of Chandi Sewou; perhaps we might get at
least a distant view. When we had walked the length of a city block
down a shady road, with carved fragments and overgrown stones
scattered along the way and through the young jungle at one side,
we turned a corner, walked another block, and stood between the
giant images that guard the entrance of Chandi Sewou’s great
quadrangle.
The “Thousand Temples” were really but two hundred and thirty-
six temples, built in five quadrilateral lines around a central cruciform
temple, the whole walled inclosure measuring five hundred feet
either way. Many of these lesser shrines—mere confessional boxes
in size—are now ruined or sunk entirely in the level turf that covers