Google Groupes n'accepte plus les nouveaux posts ni abonnements Usenet. Les contenus de l'historique resteront visibles.

Adverbs

9 vues
Accéder directement au premier message non lu

Jonathan Lang

non lue,
24 avr. 2006, 21:58:0424/04/2006
à perl6language,
How do you define new adverbs, and how does a subroutine go about
accessing them?

--
Jonathan Lang

Larry Wall

non lue,
24 avr. 2006, 22:12:1624/04/2006
à 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

non lue,
24 avr. 2006, 23:30:0424/04/2006
à 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

non lue,
25 avr. 2006, 00:02:0525/04/2006
à 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

non lue,
25 avr. 2006, 00:27:1225/04/2006
à 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

non lue,
25 avr. 2006, 01:18:2325/04/2006
à 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 nouveau message