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.
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 schw...@pobox.com http://www.pobox.com/~schwern/ Now we come to that part of the email you've all been waiting for--the end.
> 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". :-)
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.
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.
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).
On Mon, 2003-11-24 at 16:00, Luke Palmer wrote: > 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.
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.
> 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.
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 d...@lighthouse.tamucc.edu
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.
On Tue, Nov 25, 2003 at 01:46:39PM -0700, John Williams wrote: > 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
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.
-Scott -- Jonathan Scott Duff d...@lighthouse.tamucc.edu
> -----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) {...}
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.
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.
> > -----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.
> 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.
> 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.
dam...@conway.org (Damian Conway) wrote in message <news:3FC2AE89.5060908@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.
> > "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?