Franken said:
In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe:
I see this as a contrast to perl. All six args find their way to the
output:
C:\MinGW\source>perl gg1.pl
Mon => Monday
Sun => Sunday
Tue => Tuesday
C:\MinGW\source>type gg1.pl
#!/usr/bin/perl
# perl gg1.pl
use strict;
use warnings;
my %longday1 =
(
("Sun" , "Sunday"),
("Mon" ,"Monday"),
( "Tue" ,"Tuesday"),
);
in perl, whether ("Sun", "Sunday") is recognized as a list containing
two string elements separated by a comma or as a parenthesized comma
expression with a value of "Sunday" depends upon whether it occurs in
a list context or a scalar context. Since this is a list context, none
of those commas are comma operators. Try the following, where all of
the commas are comma operators:
my $longday2 =
(
("Sun" , "Sunday"),
("Mon" ,"Monday"),
("Tue" ,"Tuesday"),
);
You will find that $longday2 has a value of "Tuesday".
The definition of %longday1 given above is syntactically comparable
(the semantics are quite different) to the C definition:
char *longday3[][2] =
{
{"Sun" , "Sunday"},
{"Mon" ,"Monday"},
{"Tue" ,"Tuesday"},
};
where the commas are also not comma operators. In C, the fact that
commas separating elements of an initializer list are not comma
operators is indicated by the fact that the grammar requires that
elements of initializer lists must be assignment-expressions. The
result of applying the comma operator is an expression, but it doesn't
qualify as an assignment-expression.
If you parenthesize an expression, it becomes a primary expression,
which does qualify as as an assignment expression. It would,
therefore, be perfectly possible to have comma operator in an
initializer, but only if it is parenthesized. Three of the six commas
in the following declaration are comma operators:
char *longday4[] =
{
("Sun" , "Sunday"),
("Mon" ,"Monday"),
("Tue" ,"Tuesday"),
};