Skip to content

Commit d803f2b

Browse files
committed
Fix crashing example in slicing section
The first example in the slicing section fails to build as it tries to link the external symbol foo which is not provided. I also enhanced the other example to be a little bit more interesting for casual visitors. Examples which display only 'Succeed without output.' are completely useless.
1 parent b972978 commit d803f2b

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

spec/arrays.dd

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ $(H2 $(LNAME2 slicing, Slicing))
165165

166166
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
167167
---------
168-
void foo(int);
168+
void foo(int value)
169+
{
170+
writeln("value=", value);
171+
}
169172

170173
int[10] a; // declare array of 10 ints
171174
int[] b;
@@ -182,14 +185,20 @@ foo(b[1]); // equivalent to foo(3)
182185
For example, the assignments to b:
183186
)
184187

185-
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
188+
$(SPEC_RUNNABLE_EXAMPLE_RUN
186189
---------
187-
int[10] a;
188-
int[] b;
190+
int[10] a = [ 1,2,3,4,5,6,7,8,9,10 ];
191+
int[] b1, b2, b3, b4;
192+
193+
b1 = a;
194+
b2 = a[];
195+
b3 = a[0 .. a.length];
196+
b4 = a[0 .. $];
197+
writeln(b1);
198+
writeln(b2);
199+
writeln(b3);
200+
writeln(b4);
189201

190-
b = a;
191-
b = a[];
192-
b = a[0 .. a.length];
193202
---------
194203
)
195204

@@ -201,10 +210,17 @@ b = a[0 .. a.length];
201210
but for converting pointers into bounds-checked arrays:
202211
)
203212

204-
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
213+
$(SPEC_RUNNABLE_EXAMPLE_RUN
205214
---------
206-
int* p;
215+
int[10] a = [ 1,2,3,4,5,6,7,8,9,10 ];
216+
217+
int* p = &a[2];
207218
int[] b = p[0..8];
219+
writeln(b);
220+
writeln(p[7]); // 10
221+
writeln(p[8]); // undefined behaviour
222+
writeln(b[7]); // 10
223+
//writeln(b[8]); // range error
208224
---------
209225
)
210226

spec/lex.dd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ $(GNAME DecimalInteger):
600600
$(GLINK NonZeroDigit) $(GLINK DecimalDigitsUS)
601601

602602
$(GNAME BinaryInteger):
603-
$(GLINK BinPrefix) $(GLINK BinaryDigitsUS)
603+
$(GLINK BinPrefix) $(GLINK BinaryDigitsNoSingleUS)
604604

605605
$(GNAME BinPrefix):
606606
$(B 0b)
@@ -645,6 +645,12 @@ $(GNAME DecimalDigitUS):
645645
$(GLINK DecimalDigit)
646646
$(D _)
647647

648+
$(GNAME BinaryDigitsNoSingleUS):
649+
$(GLINK BinaryDigit)
650+
$(GLINK BinaryDigit) $(GLINK BinaryDigitsUS)
651+
$(GLINK BinaryDigitsUS) $(GLINK BinaryDigit)
652+
$(GLINK BinaryDigitsUS) $(GLINK BinaryDigit) $(GLINK BinaryDigitsUS)
653+
648654
$(GNAME BinaryDigitsUS):
649655
$(GLINK BinaryDigitUS)
650656
$(GLINK BinaryDigitUS) $(I BinaryDigitsUS)

0 commit comments

Comments
 (0)