Adverbs are confusing me mightily lately.

It may be that Larry's A12 revision just needs a few examples
*with* parenthesis to straighten me out.

Here are some semi-coherent attempts to sort it out
in my mind.  Please correct me where I have made mistakes.

What is the rule(s) for when :foo is an adverb, and when :foo
is just a pair constructor?

So far I think that :foo is an adverb where an operator
is expected, but :for is a pair constructor where a term
is expected.

Why is this difference important?

Perhaps because an adverb goes looking for something to
apply itself to.

How does it decide what to apply itself to?

>    4) Adverbs apply to the previous unparenthesized prefix, infix,
>    or postfix operator, bypassing simple terms and other "pill"
>    operators such as circumfix or postcircumfix.

But what about the rules for "additional arguments as adverbs"?

>    1d) Additional [function] arguments may occur as adverbs *only* if
>    there are explicit parens.

>    2d) Given 2c, additional [method] arguments may occur as adverbs
>    whether or not there is an argument "pill":

I assume rule 1d only applies to arglist parenthesis,
and not grouping parenthesis?

The legal syntaxes below all mean the same thing, right?

   func(1,2,3,:foo);  # ok
   func 1,2,3,:foo ;  # ok
   func(1,2,3):foo ;  # ok
   func(1,2,3 :foo);  # ok (explicit parens)
   func 1,2,3 :foo ;  # ILLEGAL (according to A12 revision)

And for 2d, these are the same:

   .meth(1,2,3):foo ;
   .meth(1,2,3 :foo);

Does rule 1d or rule 4 does apply inside this parenthesized arglist?

   func( eeney, meeny, miney :moe );

Does :moe apply to func (rule 1d) or miney (rule 4)?
Does it depend on the declaration of miney?

   sub miney {...}         # simple term: moe applies to func
   sub miney(*%adv) {...}  # does a slurpy hash make a function a list operator?
   sub miney($+moe) {...}  # I'll take that moe
   sub miney($+curly) {...}  # Arg OK, but not that one!

Is this correct according to 2d, assuming func and meth are 0-ary:

   say func :foo;     # say( func, foo=>1 )
   say .meth :foo;    # say( .meth( foo=>1 ) )

but if func is 2-or-more-ary, then:

   say func :foo;     # say( func( foo=>1 ) )

A unary function cannot take an adverb, because it has no slurpy hash.

Is a function with a slurpy hash automatically a list operator,
even if it has 0 or 1 positional arguments?

Do I have my whitespace rules right below?

   say  foo :bar;     # say( foo( bar=>1 ) )   assuming foo is listy
   say .foo :bar;     # say( .foo( bar=>1 ) )
   say  foo: bar;     # foo.say(bar)
   say  foo:bar ;     # ?? say foo :bar ??

Adverbs are still passed to the function as "just a pair",
so they have to come after positional parameters.

But that's kinda ugly in some cases.  Are there ways to get
around it?

If I know the names of the positional parameters, I can put the
adverb (aka pair constructor) first, and pass all the parameters
in via names.

    sub foo( $bar, $baz, %*advs) {...}
    foo :expletive bar=>3, baz=>42;

If I think my function would look better with the :adverb
next to the function, and still have positional parameters,
I can just declare foo with no named positional parameters,
and any parameters after the adverb will go in the slurpy array.

Larry also shows this example:

>     @a.sort:quick:{ +$_ }   # both adverbs apply to .sort

Would that work for the functional form too?

     sort :quick :{ +$_ } @a;

Does adverbial block find its way into the block parameter,
which was actually declared as an optional positional parameter
(of type Criteria)?

~ John Williams


Reply via email to