On Sunday, 14 April 2019 at 17:33:51 UTC, Adam D. Ruppe wrote:
That will expand to:
I'm sorry, I skipped a step here. The compiler doesn't look into
the mixin string until after it calls mixin, so technically it
goes:
static foreach ->
mixin("void print" ~ 'A' ~ "(int a) {
On Sunday, 14 April 2019 at 15:13:37 UTC, Johannes Loher wrote:
At first I was very confused that this example even worked. Why
does `ch` get expanded in the call to writeln? It is part of
the mixed in string, so why does the string not simply include
"writeln(ch, ...)" on every iteration?
Am 14.04.19 um 15:22 schrieb Adam D. Ruppe:
> [...]
> Though, I'd point out the mixin code doesn't have to be too ugly.
> Consider this:
>
> void main()
> {
> enum letters = ['A', 'B', 'C'];
>
> static foreach(ch; letters)
> {
> mixin(q{
> void print}~ch~q{(int i) {
>
On Sunday, 14 April 2019 at 12:00:38 UTC, Andrey wrote:
I want to mixin only name - not the full function code.
You can't. Best you can do is write the function separately and
then mixin an alias for it with the other name.
void main()
{
enum letters = ['A', 'B', 'C'];
// normal
On Sunday, 14 April 2019 at 12:00:38 UTC, Andrey wrote:
On Sunday, 14 April 2019 at 11:44:16 UTC, Boris Carvajal wrote:
On Sunday, 14 April 2019 at 10:07:30 UTC, Andrey wrote:
I want to mixin only name - not the full function code.
I think you can't do a partial statement in a mixin.
But
On Sunday, 14 April 2019 at 11:44:16 UTC, Boris Carvajal wrote:
On Sunday, 14 April 2019 at 10:07:30 UTC, Andrey wrote:
Create some function in loop and use it. But I don't know how
to mixin names?
import std.stdio;
void main()
{
enum letters = ['A', 'B', 'C'];
static foreach(ch;
On Sunday, 14 April 2019 at 10:07:30 UTC, Andrey wrote:
Create some function in loop and use it. But I don't know how
to mixin names?
import std.stdio;
void main()
{
enum letters = ['A', 'B', 'C'];
static foreach(ch; letters)
{
mixin("void print" ~ ch ~ "(uint i) {
Hi,
I want to do something like this:
void main()
{
enum letters = ['A', 'B', 'C'];
static foreach(ch; letter)
{
void mixin("print" ~ ch)(uint i)
{
writeln(ch, " - ", i);
}
}
printB(6);
}
Create some function in loop and use it.