Perl 6 可以采用不是第一个的位置参数吗?

Can Perl 6 assume a positional parameter that's not the first one?

Perl 6 允许您使用 .assuming 柯里化子程序。当您想假设领先的位置参数时,这很容易做到:

# The first one
{
sub first-and-last ( $first, $last ) {
    say "Name is $first $last";
    }

my &joe = &first-and-last.assuming( 'Joe' );

&joe.( 'Jones' );
}

但是,如果我想假定其他位置参数之一,而只保留第一个位置参数怎么办?我怎样才能告诉 .assuming 假设哪些参数?

# The second one
try {
sub first-and-last ( $first, $last ) {
    say "Name is $first $last";
    }

my &smith = &first-and-last.assuming( Empty, 'Smith' );

&smith.( 'Joe' );
}

使用命名参数这很简单,但这不是我好奇的地方。

如果下面真的是just an EVAL,那有点令人失望。

嗯,一个Whatever有效:

sub first-and-last ( $first, $last ) {
    say "Name is $first $last";
    }

my &smith = &first-and-last.assuming( *, 'Smith' );

&smith.( 'Joe' );

你可以处理中间参数:

sub longer-names ( $first, $middle, $last, $suffix ) {
    say "Name is $first $middle $last $suffix";
    }

my &smith = &longer-names.assuming( *, *, 'Public', * );

&smith.( 'Joe', 'Q.', 'Jr.');