How do I iterate through a list of commands with different (numbers of) parameters?

Playground

I'm trying to create a list of commands,
calling them and see how far I am progressing.
It's actually probably supposed to be a list of copy commands,
but I haven't gotten that far as of yet, so I'm using "sleep" as a placeholder.

My issue is that I'm unable to create a list of commands.

My first approach was to create a list of functions with different parameters, but I've been told that this is very messy and should be avoided.

I found my answer on the stack.

Playground

But I can't wrap my head around why I shouldn't return a reference of a command.

[edit]

Oh, because one is referencing to either a local variable, function parameter or a temporary, which are dropped by the end of the function. And the arg("arg1") function returns a reference to the command object, which I assume is a temporary.

1 Like