Bug 17040 – Examples should have an import of itself

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2016-12-28T17:46:00Z
Last change time
2017-07-12T16:48:54Z
Keywords
trivial
Assigned to
nobody
Creator
donte5379

Comments

Comment #0 by donte5379 — 2016-12-28T17:46:58Z
davidcha% dmd --version DMD64 D Compiler v2.071.2 This example is from http://dlang.org/phobos/std_algorithm_iteration.html import std.algorithm.comparison : max, min; import std.math : approxEqual; import std.range; int[] arr = [ 1, 2, 3, 4, 5 ]; // Sum all elements auto sum = reduce!((a,b) => a + b)(0, arr); assert(sum == 15); The error message is ./reduce_bug.d(17): Error: template instance reduce!((a, b) => a + b) template 'reduce' is not defined Failed: ["dmd", "-v", "-o-", "./reduce_bug.d", "-I."] It will compile and run if the import statement is changed to either of the following: import std.algorithm; import std.algorithm.iteration;
Comment #1 by greeenify — 2016-12-29T09:03:57Z
Hmm obviously you need to import the respective module. However, it could make sense to print this as well in the docs, s.t. one can copy/paste easier (thus I am renaming this enhancement request).
Comment #2 by greensunny12 — 2017-07-12T16:48:54Z
Since a couple of weeks we have a export button on the right which takes you to run.dlang.io (and interactive playground). On export the current module + std.stdio are imported and the code is wrapped into a void main() { ...}, s.t. it's runnable everywhere. I am hence closing this as FIXED, please reopen if you disagree and still think that the examples should have the respective imported modules directly listed on dlang.org, please reopen.