comma operator

S

sln

In Dread Ink, the Grave Hand of Lawrence Statton Did Inscribe:


For the record, it is uri, the person half my size and halfway around the
world, who dropped the f-bomb, ungrammatically, first.

Lawrence is the type of person to killfile a person with whom he has had no
interaction.

Makes you wonder what his motive is, because it has nothing to do with me.

Your an absoluted dick head. What are your motives?
Attention whore, thats what.

-sln
 
A

A. Sinan Unur

....

Uri Guttman responded to a post that I clearly marked as a mispost
with a sentence that included the words "dumb ****" and seems to think
the problem is that I get answers.

You might want to make thedailywtf.com your daily reading.

Oh, and Uri never used the phrase "dumb f**k". You lied.

Bye bye.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
F

Franken Sense

In Dread Ink, the Grave Hand of Nathan Keel Did Inscribe:
$comments{$counter} = $comment;

Thx. I couldn't see the difference.
--
Frank

I once asked the most fabulous couple I know, Madonna and Guy Ritchie, how
they kept things fresh despite having been married for almost seven months.
'It's a job, Al,' Guy told me. 'We work at it every day.'
~~ Al Franken,
 
C

Charlton Wilbur

FS> In Dread Ink, the Grave Hand of Nathan Keel Did Inscribe:

FS> Thx. I couldn't see the difference. -- Frank

Consider choosing a different font for your terminal window or your
IDE. The difference between ( and { is fairly significant.

Charlton
 
F

Franken Sense

In Dread Ink, the Grave Hand of Charlton Wilbur Did Inscribe:
FS> In Dread Ink, the Grave Hand of Nathan Keel Did Inscribe:


FS> Thx. I couldn't see the difference. -- Frank

Consider choosing a different font for your terminal window or your
IDE. The difference between ( and { is fairly significant.

Charlton

My sysadmin buddy thought I should continue with perl using Eclipse.
 
C

Charlton Wilbur

FS> In Dread Ink, the Grave Hand of Charlton Wilbur Did Inscribe:

FS> My sysadmin buddy thought I should continue with perl using
FS> Eclipse.

Yes, and? Has Eclipse suddenly been altered so that you cannot change
the font? Or do you not recognize "IDE" as a general term for the class
of things of which Eclipse is a member?

Charlton
 
F

Franken Sense

In Dread Ink, the Grave Hand of Charlton Wilbur Did Inscribe:
FS> In Dread Ink, the Grave Hand of Charlton Wilbur Did Inscribe:


FS> My sysadmin buddy thought I should continue with perl using
FS> Eclipse.

Yes, and? Has Eclipse suddenly been altered so that you cannot change
the font? Or do you not recognize "IDE" as a general term for the class
of things of which Eclipse is a member?

Charlton

I couldn't say. This chapter of my programming is, to be frank,
embarrassing. I had all the language and implementation issues at the same
time that my eyesight failed somewhat.

Now, I buy eyeglasses for a dollar.

Activestate is what has been my workhorse. I'm oblidged to see what
Eclipse can do.

My dos window is not where I see ( as opposed to {.
 
K

Keith Thompson

Franken Sense said:
I wonder whether this is something that has been baffling me for as long as
I've been looking at source in C-like languages, as with the following:

my ($since, @arts)=time-10*60*60;
for (reverse $first..$last) {
my %hdr=map /^(\S[^:]+):\s(.*)$/g, @{$nntp->head($_)};
defined(my $date=$hdr{'NNTP-Posting-Date'}) or next;
defined(my $time=str2time $date)
or warn "Couldn't parse date for article $_ ($date)\n"
and next;
last if $time < $since;
unshift @arts, $_;
}

I think this is an example of the comma operator that purports to be the
same as C's. I think it puts RHS into the scalar $since and simply
declares @arts as an array.

I see no comma operator in that Perl code. (I see things I would have
done differently, but I won't get into that in comp.lang.c.)
I'm also still scratching my head with this from n1256.pdf:

The left operand of a comma operator is evaluated as a void expression;
there is a sequence point after its evaluation. Then the right operand is
evaluated; the result has its type and value.

Do any of the examples posted show this as a distinction that matters?

What distinction are you referring to? Distinction between what and
what, exactly?
 
F

Franken Sense

In Dread Ink, the Grave Hand of Ike Naar Did Inscribe:
Franken Sense <[email protected]> wrote:

[x-posted to clp.misc]
A little experimentation shows that the warning is given for
the ``2'' expression.
No idea why it's the only expression that triggers this warning.
Does it really matter?

I wonder whether this is something that has been baffling me for as long as
I've been looking at source in C-like languages, as with the following:

my ($since, @arts)=time-10*60*60;
for (reverse $first..$last) {
my %hdr=map /^(\S[^:]+):\s(.*)$/g, @{$nntp->head($_)};
defined(my $date=$hdr{'NNTP-Posting-Date'}) or next;
defined(my $time=str2time $date)
or warn "Couldn't parse date for article $_ ($date)\n"
and next;
last if $time < $since;
unshift @arts, $_;
}

I think this is an example of the comma operator that purports to be the
same as C's. I think it puts RHS into the scalar $since and simply
declares @arts as an array.

I'm also still scratching my head with this from n1256.pdf:

The left operand of a comma operator is evaluated as a void expression;
there is a sequence point after its evaluation. Then the right operand is
evaluated; the result has its type and value.

Do any of the examples posted show this as a distinction that matters?
--
Frank

I would never ordinally say this, but... is there any way you can get to a
pound cake?
~~ Al Franken
 
T

Tad J McClellan

["Followup-To:" header set to comp.lang.perl.misc.]


Franken Sense said:
my ($since, @arts)=time-10*60*60;

[snip other code that has nothing to do with an example of the comma operator]
I think this is an example of the comma operator that purports to be the
same as C's.


You think wrong then.

The 2nd paragraph of the docs for Perl's comma operator point out that
the comma above is "just the list argument separator";
 
K

Keith Thompson

Franken Sense said:
In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe: [...]
I see no comma operator in that Perl code. (I see things I would have
done differently, but I won't get into that in comp.lang.c.)

Alright, well, I'm just going to give up the ghost on this one. The idiom
above was from Michele Dondi. I thought comparing these operators in two
different syntaxes would be illuminating.

Comparing the use of the comma operator in C and Perl might be
illuminating. You just have to compare code that actually uses it.

On the other hand, just looking at the comma operator for one language
should tell you all you need to know about the comma operator in that
language. Its use is very similar in C and in Perl. (But Perl has so
many contexts in which the comma means something else that it's
probably not as common as in C.)

[...]
 
F

Franken Sense

In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe:
I wonder whether this is something that has been baffling me for as long as
I've been looking at source in C-like languages, as with the following:

my ($since, @arts)=time-10*60*60;
for (reverse $first..$last) {
my %hdr=map /^(\S[^:]+):\s(.*)$/g, @{$nntp->head($_)};
defined(my $date=$hdr{'NNTP-Posting-Date'}) or next;
defined(my $time=str2time $date)
or warn "Couldn't parse date for article $_ ($date)\n"
and next;
last if $time < $since;
unshift @arts, $_;
}

I think this is an example of the comma operator that purports to be the
same as C's. I think it puts RHS into the scalar $since and simply
declares @arts as an array.

I see no comma operator in that Perl code. (I see things I would have
done differently, but I won't get into that in comp.lang.c.)

Alright, well, I'm just going to give up the ghost on this one. The idiom
above was from Michele Dondi. I thought comparing these operators in two
different syntaxes would be illuminating. Now that I've seen C and some
perl with it, I can state one fact: fortran has no comma operators.
What distinction are you referring to? Distinction between what and
what, exactly?

It's a distinction I wanted to address if I weren't behind in the count by
seven strikes. Andere mal.

Disgression, aka, bugging out, is the better part of valor.
--
Frank

Most of us here in the media are what I call infotainers...Rush Limbaugh is
what I call a disinfotainer. He entertains by spreading disinformation.
~~ Al Franken
 
K

Keith Thompson

Franken Sense said:
In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe:
Comparing the use of the comma operator in C and Perl might be
illuminating. You just have to compare code that actually uses it.

On the other hand, just looking at the comma operator for one language
should tell you all you need to know about the comma operator in that
language. Its use is very similar in C and in Perl. (But Perl has so
many contexts in which the comma means something else that it's
probably not as common as in C.)

Perl has many, newfangled operators, and I was hoping to do double damage
by figuring out about the comment operator in C and the => operator in
perl, which is integral to a hash, which is their "one size fits all"
abstract data structure. [snip]
So, if there is a correspondence between => and the comma operator in perl,
and a correspondence between the comma operators in both syntaxes, and
assumed transitivity, what gets evaluated as a void expression here, and
what would happen to the hash if the types on the RHS didn't match each
other?

Understanding Perl's use of "=>" or "," for hashes, or more generally
in list context, will not help you to understand C's comma operator.

For Perl, read "perldoc perlop" and search for "Comma Operator". If
you have any questions, please direct them to comp.lang.perl.misc, not
to comp.lang.c.

As for C's comma operator, I think it's already been explained. The
only really tricky thing about it is that the comma delimiter is used
in a number of contexts where it's not an operator. A rule of thumb
that you might find useful is this: if the result of whatever appears
to the left of a comma is not discarded, then it's not a comma
operator. For example, in a function call func(arg1, arg2), the value
of arg1 is passed to the function, not discarded.
 
F

Franken Sense

In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe:
Comparing the use of the comma operator in C and Perl might be
illuminating. You just have to compare code that actually uses it.

On the other hand, just looking at the comma operator for one language
should tell you all you need to know about the comma operator in that
language. Its use is very similar in C and in Perl. (But Perl has so
many contexts in which the comma means something else that it's
probably not as common as in C.)

Perl has many, newfangled operators, and I was hoping to do double damage
by figuring out about the comment operator in C and the => operator in
perl, which is integral to a hash, which is their "one size fits all"
abstract data structure.

I think this shows an elementary use of => :

#!/usr/bin/perl
# perl gg3.pl

use strict;
use warnings;


my %longday1 =
(
"Sun" => "Sunday",
"Mon" => "Monday",
"Tue" => "Tuesday",
);

foreach my $key (sort keys %longday1)
{
print "$key => $longday1{$key}\n";
}



#!/usr/bin/perl
# perl gg1.pl

use strict;
use warnings;


my %longday1 =
(
("Sun" , "Sunday"),
("Mon" ,"Monday"),
( "Tue" ,"Tuesday"),
);

foreach my $key (sort keys %longday1)
{
print "$key => $longday1{$key}\n";
}

So, if there is a correspondence between => and the comma operator in perl,
and a correspondence between the comma operators in both syntaxes, and
assumed transitivity, what gets evaluated as a void expression here, and
what would happen to the hash if the types on the RHS didn't match each
other?
 
G

Guest

Perl has many, newfangled operators, and I was hoping to do double damage
by figuring out about the comment operator in C and the => operator in
perl, which is integral to a hash, which is their "one size fits all"
abstract data structure.

I take it you meant "the *comma* operator in C". Just in case you
didn't,
there is no "comment operator" in C

<snip>
 
K

Keith Thompson

Franken Sense said:
In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe:

I see this as a contrast to perl.

The only real contrast is that Perl refers to a comma in list context
as a "comma operator", and C doesn't. (C doesn't really have a "list
context", but it has things that are similar; initializers and
function-call argument lists are both things that Perl treats as "list
context".) In both cases (Perl comma operator in list context, C
comma that's not an operator), it doesn't have the behavior of
discarding the left operand.

[...]
#!/usr/bin/perl
# perl gg1.pl

use strict;
use warnings;


my %longday1 =
(
("Sun" , "Sunday"),
("Mon" ,"Monday"),
( "Tue" ,"Tuesday"),
);

foreach my $key (sort keys %longday1)
{
print "$key => $longday1{$key}\n";
}

Here's a somewhat similar C program, using an array rather than a
hash:

#include <stdio.h>

int main(void)
{
char *longday1[] = {
"Sun", "Sunday",
"Mon", "Monday",
"Tue", "Tuesday"
};
int i;

for (i = 0; i < sizeof longday1 / sizeof longday1[0]; i ++) {
puts(longday1);
}
return 0;
}


The point here is that the commas in the initializer for longday1 are
not comma operators; they're merely part of the syntax of an
initializer.
 
J

jameskuyper

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"),
};
 
F

Franken Sense

In Dread Ink, the Grave Hand of Keith Thompson Did Inscribe:
Franken Sense <[email protected]> writes:
As for C's comma operator, I think it's already been explained. The
only really tricky thing about it is that the comma delimiter is used
in a number of contexts where it's not an operator. A rule of thumb
that you might find useful is this: if the result of whatever appears
to the left of a comma is not discarded, then it's not a comma
operator. For example, in a function call func(arg1, arg2), the value
of arg1 is passed to the function, not discarded.

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"),
);

foreach my $key (sort keys %longday1)
{
print "$key => $longday1{$key}\n";
}

C:\MinGW\source>
 
J

jameskuyper

jameskuyper said:
Franken Sense wrote: ....

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:

That was incorrectly stated. As Keith correctly indicated, perl does
indeed refer to those as "comma operators", both in a list context and
in a scalar context, though the operation they perform is quite
different in those two cases. Only the scalar context operation
corresponds to what C calls a "comma operator".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,037
Latest member
MozzGuardBugs

Latest Threads

Top