Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The C Comma

5 views
Skip to first unread message

Luke Palmer

unread,
Nov 24, 2003, 7:00:38 PM11/24/03
to Language List
Honestly you guys, I'm not trolling. I'm just getting a lot of ideas
recently. :-)

The C comma has always bugged me, but its function is indeed useful
(many times I use C<and> in its place, if I know the left side will
always be true). I don't know whether it's staying or not (I've heard
rumors of both), but I'd suggest that it leave and allow itself to be
replaced by a word, alongside C<and>, C<or>, and C<err>.

This word: C<then>.

So, from a recent script of mine:

my $n;
while $n++ then @accum < $total {
...
}

(Where I got in trouble for using C<and> and never executing anything :-)

To me, it's very clear what's going on, and eliminates the mystery of
the comma in scalar context for a syntax error.

Luke

Michael G Schwern

unread,
Nov 24, 2003, 7:40:23 PM11/24/03
to Luke Palmer, Language List
On Mon, Nov 24, 2003 at 05:00:38PM -0700, Luke Palmer wrote:
> The C comma has always bugged me, but its function is indeed useful
> (many times I use C<and> in its place, if I know the left side will
> always be true). I don't know whether it's staying or not (I've heard
> rumors of both), but I'd suggest that it leave and allow itself to be
> replaced by a word, alongside C<and>, C<or>, and C<err>.

It certainly would solve the annoying Perl 5 "is it a list constructor or
the comma operator?" No more user confusion and simpler parsing. Maybe
even eliminate some more parens! @foo = 1,2,3;

That reason alone is enough for me.


> This word: C<then>.
>
> So, from a recent script of mine:
>
> my $n;
> while $n++ then @accum < $total {
> ...
> }
>
> (Where I got in trouble for using C<and> and never executing anything :-)
>
> To me, it's very clear what's going on, and eliminates the mystery of
> the comma in scalar context for a syntax error.

I definately agree that this is used rarely enough that it should be a word
and not a single character.

"then" sounds too much like "if/then" which is confusing. Its exactly
the opposite from what you're trying to convey.

It also doesn't convey anything about "evaluate the left hand side, ignore
the results and evaluate the right". Unfortunately, I don't have a better
name.


--
Michael G Schwern sch...@pobox.com http://www.pobox.com/~schwern/
Now we come to that part of the email you've all been waiting for--the end.

Jonathan Worthington

unread,
Nov 24, 2003, 7:49:43 PM11/24/03
to Luke Palmer, Language List
> Honestly you guys, I'm not trolling. I'm just getting a lot of ideas
> recently. :-)
Honestly, I'm not an expert on Perl 6 syntax. (And I actually am being
honest... ;-) But I'll throw in my 2 cents anyway. :-)

> <snipah>


>
> This word: C<then>.
>
> So, from a recent script of mine:
>
> my $n;
> while $n++ then @accum < $total {
> ...
> }
>
> (Where I got in trouble for using C<and> and never executing anything :-)
>
> To me, it's very clear what's going on, and eliminates the mystery of
> the comma in scalar context for a syntax error.

To me the word "then" suggests an action based upon what has happened before
(as in, if true then do this). Maybe I'm just intoxicated with BASIC, but I
still mentally read if constructs as "if conditions then { block }". I know
you're thinking "do this then do this", but it just doesn't rub me the right
way.

As for punctuation vs word, I'm really not sure. A , seems kinda natural to
me, but a word would be more useful for writing poetry.

As for it being an unused feature that could be amplified by better
syntax...I guess I can buy that. I'd just rather not buy it with a keyword
like "then". :-)

Jonathan


Rod Adams

unread,
Nov 24, 2003, 8:04:06 PM11/24/03
to Michael G Schwern, Luke Palmer, Language List
At 04:40 PM 11/24/2003 -0800, Michael G Schwern wrote:
>I definately agree that this is used rarely enough that it should be a word
>and not a single character.
>
>"then" sounds too much like "if/then" which is confusing. Its exactly
>the opposite from what you're trying to convey.
>
>It also doesn't convey anything about "evaluate the left hand side, ignore
>the results and evaluate the right". Unfortunately, I don't have a better
>name.

C<andthen>

Of course I've always thought the semicolon would have been a better choice
for the "C comma". That way C<($a, $b, $c)> would always be a list, and
C<($a; $b; $c)> would be $c, after $a and $b are evaled. I haven't thought
out how much havoc this would cause the parser, but from this programmers
view, it seems pretty intuitive.

-- Rod


Damian Conway

unread,
Nov 24, 2003, 8:21:13 PM11/24/03
to Michael G Schwern, Luke Palmer, Language List
I'm very much in favour of heteronymifying scalar vs list comma too.
Or else eliminating one of them.

Schwern wrote:

> "then" sounds too much like "if/then" which is confusing.

Why? "if/then" has never been Perl syntax.


> It also doesn't convey anything about "evaluate the left hand side, ignore
> the results and evaluate the right".

I think that's exactly what it conveys:

The suspect drank half a dozen double whiskys then drove into a lake.

Sounds *exactly* like ignoring the results of the left hand side to me. ;-)


> Unfortunately, I don't have a better name.

I don't think there *is* a better word.


Of course, it may well be that, given the rarity of scalar commas, a better
alternative is to simply eliminate them entirely and insist that people use
C<do{...;...;...}> instead.

Damian

Gregor N. Purdy

unread,
Nov 24, 2003, 8:29:57 PM11/24/03
to Luke Palmer, Language List
Luke --

I guess it might be nice to just do that with a block...

my $n;
while { $n++; @accum } < $total {
...;
}

since we already have a nice do-this-then-do-this syntax.

Sure, it looks a little weird in a for loop:

for ($i = 0; $i < $X; { $i++; some_func() }) {
...;
}


but they are already weird anyway.


FWIW, In the (hypothetical) future Jako (see parrot's
languages/jako/docs/future.pod), I've toyed with a few different ways of
looking at these sorts of constructs, one of which is this (I've made it
look a *little* more Perlish than in future.pod):

You can still write for() like this:

for ($i = 0; $i < l;$ i++) { print $x[$i], "\n" }

but it is really shorthand for this (there's a nit here wrt mapping
"for (my $i ...)" to something reasonable):

for { $i = 0 } { $i < l } { $i++ } { print $x[$i], "\n" }

or, more verbosely:

for {
$i = 0;
} while {
$i < l
} continue {
$i++
} do {
print $x[$i], "\n"
}

That is, the construct:

( ...; ...; ...; )

is another way of saying

{ ... } { ... } { ... }

which, in the case of for(), is interpreted as

{ ... } while { ... } continue { ... }

when each of the "..." is a single statement. For any case where you
want to use more than one statement for one of the "...", you just use
the more verbose syntax.

Now, that won't map directly to Perl 6, since it will handle continue
differently inside the "do" part (right?), but it fits my mental model
nicely (this idea came from looking at looping constructs from Eiffel
as well as elsewhere and looking for the unifying stuff).


Regards,

-- Gregor

--
Gregor Purdy gre...@focusresearch.com
Focus Research, Inc. http://www.focusresearch.com/

Michael G Schwern

unread,
Nov 24, 2003, 8:44:01 PM11/24/03
to Damian Conway, Luke Palmer, Language List
On Tue, Nov 25, 2003 at 12:21:13PM +1100, Damian Conway wrote:
> >"then" sounds too much like "if/then" which is confusing.
>
> Why? "if/then" has never been Perl syntax.

A lot of people read "if (foo) { bar }" as "if foo then bar" in their heads.
I'm one of them. Its not a previous syntax thing, its a translation to
English thing.

This may be a consequence of the example used

while $n++ then $foo > $bar

which I immediately associated with.

if $n++ then $foo > $bar

I didn't say it makes sense, but that's the rather strong association I have.

Damian Conway

unread,
Nov 24, 2003, 9:03:19 PM11/24/03
to Michael G Schwern, Luke Palmer, Language List
Schwern observed:

> A lot of people read "if (foo) { bar }" as "if foo then bar" in their heads.
> I'm one of them. Its not a previous syntax thing, its a translation to
> English thing.

Fair enough. It's not something I do myself, but I can see that many people
might prefer to.


> This may be a consequence of the example used
>
> while $n++ then $foo > $bar
>
> which I immediately associated with.
>
> if $n++ then $foo > $bar

Yeah, I can certainly see that.

Perhaps this is yet another argument for insisting on:

while do {$n++; $foo > $bar}

instead.

Because, like you, I sure would like to be able to get rid of those parens
around comma'd lists.

Damian

Kevin Walker

unread,
Nov 25, 2003, 9:19:02 AM11/25/03
to
sch...@pobox.com (Michael G Schwern) wrote in message news:<20031125004...@windhund.schwern.org>...

> Unfortunately, I don't have a better name.

"also"?

Jonathan Scott Duff

unread,
Nov 24, 2003, 8:38:31 PM11/24/03
to Michael G Schwern, Luke Palmer, Language List
On Mon, Nov 24, 2003 at 04:40:23PM -0800, Michael G Schwern wrote:
> On Mon, Nov 24, 2003 at 05:00:38PM -0700, Luke Palmer wrote:
> > my $n;
> > while $n++ then @accum < $total {
> > ...
> > }
> >
> > (Where I got in trouble for using C<and> and never executing anything :-)
> >
> > To me, it's very clear what's going on, and eliminates the mystery of
> > the comma in scalar context for a syntax error.
>
> I definately agree that this is used rarely enough that it should be a word
> and not a single character.
>
> "then" sounds too much like "if/then" which is confusing. Its exactly
> the opposite from what you're trying to convey.

I agree.

As long as we're fantasizing about alternate names for comma, how
about "also":

while $n++ also @accum < $total { ... }

or maybe throw some latin in there

while $n++ et @accum < $total { ... }
while $n++ cum @accum < $total { ... } # maybe?

but that's probably more obscure than the comma.

Okay, so I don't have any good ideas either, but I like "also" if
we're getting rid of the "C comma".

-Scott
--
Jonathan Scott Duff
du...@lighthouse.tamucc.edu

Smylers

unread,
Nov 25, 2003, 2:01:04 AM11/25/03
to perl6-l...@perl.org
Damian Conway writes:

> Perhaps this is yet another argument for insisting on:
>
> while do {$n++; $foo > $bar}
>
> instead.

Yes please! Is anybody here a fan of the C comma? I don't think I've
ever used it -- well, not intentionally, anyway -- but these are the
situations where I've spotted it being used:

* iterating through multiple variables at once in a C-style C<for>
loop (now C<loop>) -- this style of loop is rare itself in ideomatic
Perl, and the Perl 6 C<for> syntax provides ways of looping with
several variables

* golf -- but I'm assuming that we aren't (purposefully) adding in
features just for golfing reasons

* constructs such as this [Perl 5]:

warn "Invalid data", next unless /^\s*(\w+)\s*=\s*(.*)/ || /^\s*$/;

Doing something else just before C<next> to abort a loop iteration
is fairly common. I dislike the above line because I find the order
it evaluates in so awkward (end then start then middle), so always
find some other way of expressing such logic.

But it appears that many people do like using C<,> in this way, so
removing it may be controversial.

> Because, like you, I sure would like to be able to get rid of those
> parens around comma'd lists.

I think the last time this came up[*0] Larry said that he was going to
make:

my @num = 2, 97, 44;

'work' by fiddling with the precedence rules. That sounds good, but I'd
still prefer the C comma to go away entirely.

[*0] Possibly in response to the proposal, synthesized into an RFC by
Luke, that square brackets rather than parens be used to denote lists.

Smylers

John Williams

unread,
Nov 25, 2003, 3:46:39 PM11/25/03
to Jonathan Scott Duff, Language List
On Mon, 24 Nov 2003, Jonathan Scott Duff wrote:
> or maybe throw some latin in there
>
> while $n++ et @accum < $total { ... }
> while $n++ cum @accum < $total { ... } # maybe?

I think "ac" is the latin conjunction you want.

ac : conj. and, and also, and besides


Mark J. Reed

unread,
Nov 25, 2003, 3:54:04 PM11/25/03
to Language List

Perhaps an enclitic form?

while $n++ (@accum < $total)que { ... }

;-)

--
Mark REED | CNN Internet Technology
1 CNN Center Rm SW0831G | mark...@cnn.com
Atlanta, GA 30348 USA | +1 404 827 4754

Adam Turoff

unread,
Nov 25, 2003, 4:03:43 PM11/25/03
to Damian Conway, perl6-l...@perl.org
On Tue, Nov 25, 2003 at 01:03:19PM +1100, Damian Conway wrote:
> Schwern observed:

> >This may be a consequence of the example used
> >
> > while $n++ then $foo > $bar
> >
> >which I immediately associated with.
> >
> > if $n++ then $foo > $bar
>
> Yeah, I can certainly see that.
>
> Perhaps this is yet another argument for insisting on:
>
> while do {$n++; $foo > $bar}
>
> instead.

That looks like syntactic sugar for

while (do) {$n++; $foo > $bar}

and could be interpreted as either:

while "do" {...} ## perl5 bareword
while do() {...}

Luke's "then" feels like the best fit on the one hand, and the worst fit
on the other. Everything else feels worse, though.

Z.

Gordon Henriksen

unread,
Nov 25, 2003, 1:56:16 PM11/25/03
to Damian Conway, Language List
Damian Conway wrote:

> Micheal G. Schwern wrote:
>
> > It also doesn't convey anything about "evaluate the left
> > hand side, ignore the results and evaluate the right".
>
> I think that's exactly what it conveys:
>
> The suspect drank half a dozen double whiskys then drove
> into a lake.
>
> Sounds *exactly* like ignoring the results of the left hand
> side to me. ;-)

Not to be a wet-blanket grammar nazi, but the sentence you give as an
example isn't proper English. "Then" is an adverb,* not a conjugation.

The suspect drank half a dozen double whiskeys;
then he drove into a lake.

The suspect drank half a dozen double whiskeys
and then drove into a lake.

--

Gordon Henriksen
IT Manager
ICLUBcentral Inc.
gor...@iclub.com

* - It's also a sometimes a noun ("live has been hard since then") and
rarely an adjective ("the then president").


Gordon Henriksen

unread,
Nov 25, 2003, 2:00:26 PM11/25/03
to du...@lighthouse.tamucc.edu, Language List
Jonathan Scott Duff wrote:

> or maybe throw some latin in there
>
> while $n++ et @accum < $total { ... }
> while $n++ cum @accum < $total { ... } # maybe?

"Et," of course, is unsuitable as a direct synonym for "and."

I'm afraid that adding the second would cause Perl source code
to trigger spam filters...

Jonathan Scott Duff

unread,
Nov 25, 2003, 3:55:51 PM11/25/03
to John Williams, Language List

Actually, I've become more convinced that I don't want any of these
:-)

while do { $x++; @a < 5 } { ... }

or something like that is fine with me.

Austin Hastings

unread,
Nov 25, 2003, 6:36:59 PM11/25/03
to Adam Turoff, perl6-l...@perl.org

Hmm. Why not just explicitly allow semicolon when surrounded by parens?

while ($n++; $foo > $bar) {...}

Removing the parens changes the results, which is just what you'd expect
mathematically.

$f = (0, 1, 2, $n++, $foo > $bar); # List

$f = (0; 1; 2; $n++; $foo > $bar); # Sequence of statements, three
useless.

"C" style C<for> loops then look like:

for (($a = 0; $b = $num_elts); $a < @arry; ($a++; $b -= $offset)) {...}

Which is on the one hand yucky, but on the other hand very explicit.

(I suppose I could propose using semicolon for the list separator, but that
would drive the syntax-highlighters insane, and I like syntax-highlighting.)

=Austin

PS: An immediate drawback that occurs to me is that of catching unbalanced
parens -- when the statement terminator is a valid sequence delimiter, all
the rest of the code looks like a sequence. But the first nesting closing
brace would probably catch that.

Luke Palmer

unread,
Nov 25, 2003, 6:48:08 PM11/25/03
to Austin Hastings, Adam Turoff, perl6-l...@perl.org
Austin Hastings writes:
>
>
> > -----Original Message-----
> > From: Adam Turoff [mailto:zi...@panix.com]
> > On Tue, Nov 25, 2003 at 01:03:19PM +1100, Damian Conway wrote:
> > > Schwern observed:
>
> > > Perhaps this is yet another argument for insisting on:
> > >
> > > while do {$n++; $foo > $bar}
> > >
> > > instead.
> >
> > That looks like syntactic sugar for
> >
> > while (do) {$n++; $foo > $bar}
> >
> > and could be interpreted as either:
> >
> > while "do" {...} ## perl5 bareword
> > while do() {...}
> >
> > Luke's "then" feels like the best fit on the one hand, and the worst fit
> > on the other. Everything else feels worse, though.
>
> Hmm. Why not just explicitly allow semicolon when surrounded by parens?
>
> while ($n++; $foo > $bar) {...}

Well, because the intent of the original proposal was to "fatten up" the
C comma to make it explicit, easy to see, and clearly unambiguous. A
semicolon does none of these things. It also, as you mention, prevents
the compiler from catching a rather common syntax error.

But other than that, uh, sure. Providing we spell parens C< do{} >. :-)

> Removing the parens changes the results, which is just what you'd expect
> mathematically.
>
> $f = (0, 1, 2, $n++, $foo > $bar); # List
>
> $f = (0; 1; 2; $n++; $foo > $bar); # Sequence of statements, three
> useless.
>
> "C" style C<for> loops then look like:
>
> for (($a = 0; $b = $num_elts); $a < @arry; ($a++; $b -= $offset)) {...}

By which you mean

loop ($a = 0; $b = $num_elts); $a < @arry; ($a++; $b -= $offset)
{...}

right?

Perhaps my favorite syntactic thing Perl 6 has done so far is gotten rid
of those dastardly parens on control constructs! Yay!

Luke

Gordon Henriksen

unread,
Nov 25, 2003, 4:13:22 PM11/25/03
to Adam Turoff, Damian Conway, perl6-l...@perl.org
Adam Turoff wrote:

> Damian Conway wrote:
>
> > Perhaps this is yet another argument for insisting on:
> >
> > while do {$n++; $foo > $bar}
> >
> > instead.
>
> That looks like syntactic sugar for
>
> while (do) {$n++; $foo > $bar}

do is not merely prototyped, but a builtin. With a mandatory {} arg, why
wouldn't it be greedy?

On the other hand, ()-less conditionals are giving me heebie-jeebies
very distinctly reminiscent of Perl 5's indirect object method
invocation syntax.

John Macdonald

unread,
Nov 25, 2003, 7:52:52 PM11/25/03
to Luke Palmer, Austin Hastings, Adam Turoff, perl6-l...@perl.org
On Tue, Nov 25, 2003 at 04:48:08PM -0700, Luke Palmer wrote:
> Austin Hastings writes:
> > "C" style C<for> loops then look like:
> >
> > for (($a = 0; $b = $num_elts); $a < @arry; ($a++; $b -= $offset)) {...}
>
> By which you mean
>
> loop ($a = 0; $b = $num_elts); $a < @arry; ($a++; $b -= $offset)
> {...}
>
> right?
>
> Perhaps my favorite syntactic thing Perl 6 has done so far is gotten rid
> of those dastardly parens on control constructs! Yay!

That combination means that in "for ( ; ; ) { }" the
parens are required, yet in "loop ; ; { }" they are
disallowed. (Anything in parens immediately following
the keyword would be just the init portion, it could
no longer contain all three parts.) So, not just the
keyword name, but the syntax is required to change.

Paul Hodges

unread,
Nov 26, 2003, 4:39:50 PM11/26/03
to
dam...@conway.org (Damian Conway) wrote in message news:<3FC2AE89...@conway.org>...

> I'm very much in favour of heteronymifying scalar vs list comma too.
> Or else eliminating one of them.

I definitely use the C-style comma, but would prefer eliminating it.
I can write that code another way.

> Schwern wrote:
>
> > "then" sounds too much like "if/then" which is confusing.
>
> Why? "if/then" has never been Perl syntax.
>
> > It also doesn't convey anything about "evaluate the left hand side, ignore
> > the results and evaluate the right".
>
> I think that's exactly what it conveys:
>
> The suspect drank half a dozen double whiskys then drove into a lake.
>
> Sounds *exactly* like ignoring the results of the left hand side to me. ;-)
>
> > Unfortunately, I don't have a better name.
>
> I don't think there *is* a better word.

Further down the thread, someone mentioned saying "then" in your head
when reading it into English. Okay, I can understand that, so let's
pick another word. I don't think this needs small Huffman coding; how
about "andthen"?

warn "failed: $!" andthen next unless whatever();

Some of us already use "and", though I don't think we should (even
though I do).
"andthen" is poor English, but clear enough, and pretty rarely needed
anyway, right? Personally, I like "then" better, but I thought it
wouldn't hurt to make the suggestion.

> Of course, it may well be that, given the rarity of scalar commas, a better
> alternative is to simply eliminate them entirely and insist that people use
> C<do{...;...;...}> instead.
>
> Damian

How about the case someone mentioned of

while do { ...

looking like

while "do" {...
or
while do() {...

???

I didn't see anyone respond to that yet. It didn't look like so much
of a problem to me, but maybe I just missed the subtleties?

0 new messages