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

Adverbs

8 views
Skip to first unread message

Jonathan Lang

unread,
Apr 24, 2006, 9:58:04 PM4/24/06
to perl6language,
How do you define new adverbs, and how does a subroutine go about
accessing them?

--
Jonathan Lang

Larry Wall

unread,
Apr 24, 2006, 10:12:16 PM4/24/06
to perl6language,
On Mon, Apr 24, 2006 at 06:58:04PM -0700, Jonathan Lang wrote:
: How do you define new adverbs, and how does a subroutine go about
: accessing them?

Adverbs are just optional named parameters. Most of the magic is in
the call syntax.

Larry

Jonathan Lang

unread,
Apr 24, 2006, 11:30:04 PM4/24/06
to perl6language,
Larry Wall wrote:
> Jonathan Lang wrote:
> : How do you define new adverbs, and how does a subroutine go about
> : accessing them?
>
> Adverbs are just optional named parameters. Most of the magic is in
> the call syntax.

Ah. So every part of a Capture Object has an alternate call syntax:

act $foo, @list, bar => 'baz';

is the same as

@list ==> $foo.act:bar('baz');

right?

(And if this is the case, the one capability that the adverb notation
provides that the more traditional named parameter notation doesn't
have is a way to let a particular key to exist without being defined.)

--
Jonathan "Dataweaver" Lang

Larry Wall

unread,
Apr 25, 2006, 12:02:05 AM4/25/06
to perl6language,
On Mon, Apr 24, 2006 at 08:30:04PM -0700, Jonathan Lang wrote:
: Larry Wall wrote:
: > Jonathan Lang wrote:
: > : How do you define new adverbs, and how does a subroutine go about
: > : accessing them?
: >
: > Adverbs are just optional named parameters. Most of the magic is in
: > the call syntax.
:
: Ah. So every part of a Capture Object has an alternate call syntax:
:
: act $foo, @list, bar => 'baz';
:
: is the same as
:
: @list ==> $foo.act:bar('baz');
:
: right?

You might have to write that

@list ==> $foo.act :bar('baz');

I think or the colon on the method would be taken as starting a list.
I dunno, depends on whether .act: is considered a "longest token",
I guess. I could argue it the other way as well, and :bar is a longest
token compared to :.

: (And if this is the case, the one capability that the adverb notation


: provides that the more traditional named parameter notation doesn't
: have is a way to let a particular key to exist without being defined.)

Without being specified, anyway. The default values are always defined.

Larry

Damian Conway

unread,
Apr 25, 2006, 12:27:12 AM4/25/06
to perl6language,
One other point:

> act $foo, @list, bar => 'baz';

is actually the same as:

act($foo, @list, bar => 'baz');

which might or might not dispatch to a method on $foo,
depending on whether (and how) &act is defined.

Jonathan probably meant:

act $foo: @list, bar => 'baz';

for the indirect object syntax.

Damian

Jonathan Lang

unread,
Apr 25, 2006, 1:18:23 AM4/25/06
to perl6language,
Larry Wall wrote:
> You might have to write that
>
> @list ==> $foo.act :bar('baz');
>
> I think or the colon on the method would be taken as starting a list.
> I dunno, depends on whether .act: is considered a "longest token",
> I guess. I could argue it the other way as well, and :bar is a longest
> token compared to :.

Eh? What's this bit about lists and colons? (This is one of the
things that worries me about Perl 6: there seem to be all sorts of
"edge cases" which crop up at the most unexpected times.)

--
Jonathan "Dataweaver" Lang

0 new messages