March 20, 2004
On Sat, 20 Mar 2004 17:07:34 -0500, Vathix wrote:

> Ant wrote:
> 
>> On Sat, 20 Mar 2004 21:29:46 +0000, larry cowan wrote:
>> 
>> 
>>>In C,
>>>(expr1, expr2, expr3)
>>>is a valid expression, and evaluates to the value of the rightmost
>>>subexpression.
> 
> I would, except it's common practice to use in a for loop:
> for(i = 0; i < 5; i++, s++) { ... }
> 
> The D way could be different, but what?
> for(i = 0; i < 5; {i++; s++;}) { ... }
> 
> That's not too bad, especially since the comma operator can be a bit tricky to use.

Yes, I did used it before....

Ant

March 21, 2004
>On Sat, 20 Mar 2004 17:07:34 -0500, Vathix wrote:
>
>> I would, except it's common practice to use in a for loop:
>> for(i = 0; i < 5; i++, s++) { ... }
>> 
>> The D way could be different, but what?
>> for(i = 0; i < 5; {i++; s++;}) { ... }
>> 
Usage in the pre and post sections of a for loop is a bit different in that these don't get used as a value.  You can in this way do

if (x) a=1,b=2,c=3;  without the braces or even

if (x) f(x), g(x);  to compress simple stuff and make it a quicker read.
Not so great if they're not one-liners.

The comma operator used in this way makes what would be multiple statements into a single one - the same effect as above in the for loop.



March 21, 2004
<snip>
>if (x) a=1,b=2,c=3;  without the braces or even
>
>if (x) f(x), g(x);  to compress simple stuff and make it a quicker read.
>Not so great if they're not one-liners.
</snip>

That sure seems like abuse to me. Hard for the uninitiated to read -- read "obfuscated".

The comma operator has its (few) uses, but this aint it.


March 21, 2004
Whats good comma operator use ? the only thing ive seen it used for 'reasonably' is C style macros.

On Sun, 21 Mar 2004 05:08:34 +0000 (UTC), Juan C <Juan_member@pathlink.com> wrote:

> <snip>
>> if (x) a=1,b=2,c=3;  without the braces or even
>>
>> if (x) f(x), g(x);  to compress simple stuff and make it a quicker read.
>> Not so great if they're not one-liners.
> </snip>
>
> That sure seems like abuse to me. Hard for the uninitiated to read -- read
> "obfuscated".
>
> The comma operator has its (few) uses, but this aint it.
>
>



-- 
D Newsgroup.
March 21, 2004
On Sun, 21 Mar 2004 05:08:34 +0000, Juan C wrote:

> <snip>
>>if (x) a=1,b=2,c=3;  without the braces or even
>>
>>if (x) f(x), g(x);  to compress simple stuff and make it a quicker read.
>>Not so great if they're not one-liners.
> </snip>
> 
> That sure seems like abuse to me. Hard for the uninitiated to read -- read "obfuscated".
> 
> The comma operator has its (few) uses, but this aint it.

Examples! Examples!

but, but, it's broken:

int f( int i )
{
	printf("i = %d\n", i);
	return i+14;
}

void f(int i, int j)
{
	printf("i = %d\n", i+1);
}

void main()
{
	int i = 1, j = 0;

	i = f( i , j ), f(( i , j )), f(( j , i ));

}

$ dmd T -I~/dmd/src/phobos
T.d(16): cannot implicitly convert void to int

Ant

March 21, 2004
In article <c3j80i$h4$1@digitaldaemon.com>, Juan C says...
>
><snip>
>>if (x) a=1,b=2,c=3;  without the braces or even
>>
>>if (x) f(x), g(x);  to compress simple stuff and make it a quicker read.
>>Not so great if they're not one-liners.
></snip>
>
>That sure seems like abuse to me. Hard for the uninitiated to read -- read "obfuscated".
>
>The comma operator has its (few) uses, but this aint it.
>

The uninitiated shouldn't be programming, or should learn or be taught. Obfuscated is something far more esoteric and dense - intentionally so.

Basically I agree with you,

if (x) { a=1; b=2; c=3; }

is perfectly fine.  I was saying what could be done, not advocating it.
Perhaps you'ld like to suggest some of those "few" uses for me.  As an
operator, where the value is taken from the rightmost and used, please.
Except for pre and post sections of a for loop where it's a distinct
convenience, but only that, and more of a separator than a replacement operator,
I've probably only used it in 3 or 4 of my last 300,000 lines
of code.




March 21, 2004
It appears to be evaluated from left-to-right, but the assignment is
(trying to be) using the value of the leftmost expression.  It looks like the
assignment operator is taking precedence over the comma operator.  That's
correct, I believe.  Add one more set of parens:

i = ( f(i,j), f((i,j)), f((j,i)) );



In article <pan.2004.03.21.06.17.55.247300@yahoo.ca>, Ant says...
>
>but, but, it's broken:
>
>int f( int i )
>{
>	printf("i = %d\n", i);
>	return i+14;
>}
>
>void f(int i, int j)
>{
>	printf("i = %d\n", i+1);
>}
>
>void main()
>{
>	int i = 1, j = 0;
>
>	i = f( i , j ), f(( i , j )), f(( j , i ));
>
>}
>
>$ dmd T -I~/dmd/src/phobos
>T.d(16): cannot implicitly convert void to int
>
>Ant
>


March 22, 2004
Ant wrote:
[...]
> 	assert(false, 0);
[...]
> T.d(3): found ',' when expecting ')'
[...]

You detected an inconsistency:

parse.c:
|    check(TOKlparen, "assert");
|    e = parseAssignExp();

expression.html:
|	AssertExpression:
|		assert ( Expression )

So long!
1 2
Next ›   Last »