LABELS: block

9 views
Skip to first unread message

Stevan Little

unread,
Apr 26, 2005, 11:40:10 AM4/26/05
to perl6-l...@perl.org
Hello all,

I have been going over the Synopsis, and I cannot find block labels
mentioned anywhere. I was under the impression that if it is not
mentioned, then it can be assumed to be the same as perl5. However, I
wonder if this is the case with labels given that "everybody wants the
colon".

Can anyone please confirm or deny the existence of labels for blocks in
perl6? And if yes, then point me in a helpful direction as well so I
can write up some tests?

Thanks much,

Stevan

Luke Palmer

unread,
Apr 26, 2005, 11:28:43 AM4/26/05
to Stevan Little, perl6-l...@perl.org
Stevan Little writes:
> Hello all,
>
> I have been going over the Synopsis, and I cannot find block labels
> mentioned anywhere. I was under the impression that if it is not
> mentioned, then it can be assumed to be the same as perl5. However, I
> wonder if this is the case with labels given that "everybody wants the
> colon".

Labels are pretty easy to pick out. I don't believe there is any other
thing in the language that, at the beginning of a statement, matches
/\w+\:/ . They are certainly available in Perl 6 (as are plain old line
labels; we're not getting rid of goto, to many's dismay (but not mine)).

Luke

Juerd

unread,
Apr 26, 2005, 2:01:30 PM4/26/05
to Luke Palmer, Stevan Little, perl6-l...@perl.org
Luke Palmer skribis 2005-04-26 9:28 (-0600):

> Labels are pretty easy to pick out. I don't believe there is any other
> thing in the language that, at the beginning of a statement, matches
> /\w+\:/ . They are certainly available in Perl 6 (as are plain old line
> labels; we're not getting rid of goto, to many's dismay (but not mine)).

Indirect method call on default invocant:

method: args;

Quoting:

qq:to/foo/ ==> say;
s:2nd/foo/bar/;

The latter can be fixed by requiring \w+:\s+, but the former I think
cannot.


Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html

Luke Palmer

unread,
Apr 26, 2005, 1:24:34 PM4/26/05
to Juerd, Stevan Little, perl6-l...@perl.org
Juerd writes:
> Luke Palmer skribis 2005-04-26 9:28 (-0600):
> > Labels are pretty easy to pick out. I don't believe there is any other
> > thing in the language that, at the beginning of a statement, matches
> > /\w+\:/ . They are certainly available in Perl 6 (as are plain old line
> > labels; we're not getting rid of goto, to many's dismay (but not mine)).
>
> Indirect method call on default invocant:
>
> method: args;
>
> Quoting:
>
> qq:to/foo/ ==> say;
> s:2nd/foo/bar/;
>
> The latter can be fixed by requiring \w+:\s+, but the former I think
> cannot.

That's true, but the former hasn't been accepted. That's not something
I considered when I was thinking about that proposal, but I think it's
a fairly minor issue. We'll ignore labels as we continue to weigh that
proposal, and redo label syntax later if we must.

Luke

Aaron Sherman

unread,
Apr 26, 2005, 4:40:05 PM4/26/05
to Luke Palmer, Perl6 Language List
On Tue, 2005-04-26 at 13:24, Luke Palmer wrote:

> [we'll] redo label syntax later if we must.


Well, of course you run the danger of making it hard for people to
recognize labels which are otherwise common across many languages, but
here's a few ways you could do labels if you need to:

The real problem is that you're using a trailing glyph to identify what
is essentially a type, so you could introduce a leading glyph:

rx/: <identifier> <ws>+ ( <statement> | <control> ) /

Is there ever a reason for a leading adverb in a statement or control
structure?

or you could have a keyword that introduces the label:

rx/label <ws>+ <identifier> <ws>+ (<statement>|<control>)/

or you could use some kind of trickery:

rx/label : $/

note that this means that we're making a newline part of the syntax,
which might feel "too python" to folks (especially where it ends in a
":"), but it would leave you with very P5 looking labels:

LINE:
while =<> -> $line {
CHAR:
for split('',$line) -> $char {
next CHAR if $char eq ' ';
next LINE if $char eq '#';
}
}

Of course, let leaves you not able to do:

method:
args;

And I'm not even going to start on the "if it's the same column"
thing... ;-)

--
Aaron Sherman <a...@ajs.com>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback


Juerd

unread,
Apr 26, 2005, 5:13:49 PM4/26/05
to Aaron Sherman, Luke Palmer, Perl6 Language List
Aaron Sherman skribis 2005-04-26 16:40 (-0400):

> Is there ever a reason for a leading adverb in a statement or control
> structure?

List of pairs and left-to-right writing:

:foo<bar>, :quux<xyzzy> ==> map { ... } ==> my @baz;

> or you could have a keyword that introduces the label:
> rx/label <ws>+ <identifier> <ws>+ (<statement>|<control>)/
> or you could use some kind of trickery:
> rx/label : $/

Or make it a macro.

label<foo>; for 1... {
...
}

Or an object

my $foo = for 1... {
$foo.next;
next $foo:;
}

Or just add quotes (yes, please) and keep the colon:

"foo": for 1... {
next "foo";

Dave Whipp

unread,
Apr 26, 2005, 8:58:50 PM4/26/05
to perl6-l...@perl.org
Juerd wrote:
> ...

> Or just add quotes (yes, please) and keep the colon:
>
> "foo": for 1... {
> next "foo";
> }

Given that "next" throws a control-exception that is handled by the
looping construct, perhaps we sohuld think of the label as an optional
parameter to the looping statement function

for :label<foo> 1... { next "foo" };

This makes labels somewhat less general, but maybe C<goto> should be
handled separately, anyway. For example, maybe you can only use C<goto>
if you've asked to "use continuations;".

Aaron Sherman

unread,
Apr 27, 2005, 1:19:38 PM4/27/05
to Juerd, Perl6 Language List
On Tue, 2005-04-26 at 17:13, Juerd wrote:

> > or you could have a keyword that introduces the label:
> > rx/label <ws>+ <identifier> <ws>+ (<statement>|<control>)/
> > or you could use some kind of trickery:
> > rx/label : $/
>
> Or make it a macro.
>
> label<foo>; for 1... {
> ...
> }

This has debugging problems, and might limit how and when loops can be
unrolled automatically.

[...]


> Or just add quotes (yes, please) and keep the colon:
>
> "foo": for 1... {
> next "foo";
> }

That's not so bad... but it does offend the sense that a label is an
identifier on-par with a subroutine name. Hmm... that makes me think....
"label" is a bit heavy-weight for something that used to be implicit.
Perhaps what we need is a shorter name, and then it would not seem so
bad to have to have a keyword before the label:

tag foo: for 1... {
next foo;
}

Yes, I like this for the following reasons:

* It looks very much like a sub definition ("sub foo(" ~ "tag
foo:")
* There's no parser magic. It's just rx/tag <identifier> :
(<statement> | <control>)/
* It carries the legacy of the C-derived label well, such that a C
programmer should be able to look at this code and know what it
does.
* "tag" is a short enough keyword that we're not going to clutter
code with a very semantically light-weight idiom (syntactic
complexity for semantic simplicity should indicate deprecated
constructs, and as far as I know, no one is deprecating labels).
* Tagging might be useful in other situations where a keyword
would be useful for visually marking the construct. I have no
good examples, though.

Larry Wall

unread,
May 2, 2005, 10:02:28 PM5/2/05
to perl6-l...@perl.org
On Tue, Apr 26, 2005 at 11:24:34AM -0600, Luke Palmer wrote:
: That's true, but the former hasn't been accepted. That's not something

: I considered when I was thinking about that proposal, but I think it's
: a fairly minor issue. We'll ignore labels as we continue to weigh that
: proposal, and redo label syntax later if we must.

It's looking like we won't be needing to redo label syntax, if we
accept the &.foo() proposal for self calls. (The omitted indirect
object syntax for self calls wasn't going to fly anyway, since "foo
bar:" is then too ambiguous, quite apart from the tail marking issues.)

In any event, none of the proposals that bury the label is going to
be acceptable. As a vital visual element of control flow, the label
has to be out front where it can be seen.

Larry

Juerd

unread,
May 3, 2005, 5:08:49 AM5/3/05
to perl6-l...@perl.org
Larry Wall skribis 2005-05-02 19:02 (-0700):

> In any event, none of the proposals that bury the label is going to
> be acceptable. As a vital visual element of control flow, the label
> has to be out front where it can be seen.

Something that putting quotes around them accomplishes...

(I'd still like the bareword-ish labels to go away)

Reply all
Reply to author
Forward
0 new messages