PROPOSAL: opSeq()
Bill Baxter
dnewsgroup at billbaxter.com
Mon Apr 7 16:26:00 PDT 2008
Russell Lewis wrote:
> PROPOSAL: A way to handle sequences of expressions which otherwise would
> have been syntax errors
>
>
> EXAMPLE CODE:
> my_for(i=0, i<10, i++) { <code> }
Are you familiar with the "trailing delegates" proposal?
Basically the idea there is that any {<code>} block following a function
call would be treated as an extra argument to the function.
So if you write the function:
void my_for(lazy void init, lazy bool test, lazy void inc, void delegate())
{ ... }
then your EXAMPLE_CODE above would call that function.
Your proposal would have one benefit over that in that you could have
"my_for" a varargs function if you wanted to. Though, the trailing
delegates idea could probably be fixed to handle that too. Like by
making the trailing delegate the first argument instead of the last
(kinda like what opIndexAssign does).
Overall I think trailing delegates sounds like a simpler, more elegant
approach. Can you point out any other benefits of your proposal that
trailing delegate args would not have?
I believe Walter's response previously has been that we should just get
used to looking at things like:
my_for(i=0,i<10,i++,{<code>});
instead of adding complications to the grammar to support such things.
--bb
More information about the Digitalmars-d
mailing list