Debug help - static foreach - module scope - Programming in D page 603

Brother Bill brotherbill at mail.com
Thu Aug 28 13:09:21 UTC 2025


Unable to compile.  Please advise.
```
c:\dev\D\81 - 90\c83_e_static_foreach_fibonacci\source\app.d(8): 
Error: function declaration without return type. (Note that 
constructors are always named `this`)
     writeln(n);
            ^
c:\dev\D\81 - 90\c83_e_static_foreach_fibonacci\source\app.d(8): 
Error: variable name expected after type `writeln(n)`, not `;`
     writeln(n);
               ^
```

source/app.d
```
import std.stdio;
import std.range;
import std.algorithm;

static foreach (n; FibonacciSeries().take(10).filter!isEven)
{
	writeln(n);
}

void main()
{
	foreach (n; FibonacciSeries().take(10).filter!isEven) {
		writeln(n);
	}
}

bool isEven(int n) {
	return n % 2 == 0;
}

struct FibonacciSeries
{
	int current = 0;
	int next = 1;
	enum empty = false;
	int front() const
	{
		return current;
	}

	void popFront()
	{
		const nextNext = current + next;
		current = next;
		next = nextNext;
	}

	FibonacciSeries save() const
	{
		return this;
	}
}
```



More information about the Digitalmars-d-learn mailing list