hi,
what was the reason for foreach(x; y; z)? why is it not possible to have the parser distinguish foreach(x, y) from foreach(x, y, z)? i remember reading that there is a backwards compatibility problem, but i don't see where this would be.
greetings, martin.
The question is rather what the reason for foreach (x,y) was... semicolon is much better in those statements, since comma is a valid operator, and makes the statement look like a function anyway. :)
/ Mirar
Previous text:
2004-09-26 21:23: Subject: foreach(x, y) vs foreach(x; y; z)
hi,
what was the reason for foreach(x; y; z)? why is it not possible to have the parser distinguish foreach(x, y) from foreach(x, y, z)? i remember reading that there is a backwards compatibility problem, but i don't see where this would be.
greetings, martin.
/ Brevbäraren
does this imply that ; was chosen because , was a mistake, and this has nothing to do with backwards compatibility at all?
if that is the case, then the documentation ought to reflect that, and depreciate foreach(x,y)
greetings, martin.
what was the reason for foreach(x; y; z)?
To support iterators, and support looping over both indices and values in one operation.
why is it not possible to have the parser distinguish foreach(x, y) from foreach(x, y, z)?
It is, but the semantics get strange, since y in the first case is a value, but in the second is an index.
The difference in syntax also helps detecting bugs. cf:
foreach(x,y) foreach(x,y,) foreach(x,,y)
/ Henrik Grubbström (Lysator)
Previous text:
2004-09-26 21:23: Subject: foreach(x, y) vs foreach(x; y; z)
hi,
what was the reason for foreach(x; y; z)? why is it not possible to have the parser distinguish foreach(x, y) from foreach(x, y, z)? i remember reading that there is a backwards compatibility problem, but i don't see where this would be.
greetings, martin.
/ Brevbäraren
On Mon, Sep 27, 2004 at 02:50:03PM +0200, Henrik Grubbström (Lysator) @ Pike (-) developers forum wrote:
It is, but the semantics get strange, since y in the first case is a value, but in the second is an index.
the semantics are strange anyways, having ; in the second does not help a bit here. since having 3 arguments vs 2 is already a clear visual difference larger than ; vs ,
comparing foreach(x,y) with foreach(x;y;z) is as confusing as comparing foreach(x,y) with foreach(x,y,z)
it is probably better to introduce the user to foreach(x;y;z) and foreach(x;;z) and depreciate the old foreach(x,y) completely.
thoughts?
The difference in syntax also helps detecting bugs. cf:
what kind of bugs? i don't see the difference with foreach(x;y) foreach(x;y;) foreach(x;;y)
should i teach people to always use foreach(;;) and tell them that foreach(,) is old and may be phased out?
can we get a warning for foreach(,) into pike 7.7 and should we convert all uses in the pike source? (just say yes here, and in a boring night it might happen)
greetings, martin.
pike-devel@lists.lysator.liu.se