Skip to content

Commit fe06ca8

Browse files
committed
more priming cleanup, spec .assuming * or Nil
1 parent 2b77c58 commit fe06ca8

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

S02-bits.pod

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Synopsis 2: Bits and Pieces
1313

1414
Created: 10 Aug 2004
1515

16-
Last Modified: 6 Oct 2011
17-
Version: 239
16+
Last Modified: 7 Oct 2011
17+
Version: 240
1818

1919
This document summarizes Apocalypse 2, which covers small-scale
2020
lexical items and typological issues. (These Synopses also contain
@@ -1016,21 +1016,28 @@ by marking the proto sub with the trait, C<is like-Whatever-and-stuff>.
10161016
[Conjecture: actually, this is negotiable--we might shorten it
10171017
to C<is like(Whatever)> or some such. C<:-)>]
10181018

1019-
=head3 Priming of Unary and Binary Operators with Whatever
1019+
=head3 Autopriming of Unary and Binary Operators with Whatever
1020+
1021+
Perl 6 has several ways of performing partial function application.
1022+
Since this is an unwieldy term, we've settled on calling it I<priming>.
1023+
(Many folks call this "currying", but that's not really a correct
1024+
technical usage of the term.) Most generally, priming is performed
1025+
on a C<Callable> object by calling its C<.assuming> method, described elsewhere.
1026+
This section is about a convenient syntactic sugar for that.
10201027

10211028
For any unary or binary operator (specifically, any prefix, postfix,
10221029
and infix operator), if the operator has not specifically requested
1030+
(via signature matching)
10231031
to handle C<*> itself, the compiler is required to translate directly
1024-
to an appropriately primed closure at compile time. (I<Priming> is our
1025-
term for partial function application. Many folks call this "currying", but
1026-
that's not really a correct technical usage of the term.) Most of the
1027-
built-in numeric operators fall into this category, so:
1032+
to an appropriately primed closure at compile time. We call this
1033+
I<autopriming>. Most of the built-in numeric operators fall into
1034+
this category. So:
10281035

10291036
* - 1
10301037
'.' x *
10311038
* + *
10321039

1033-
are internally primed into closures of one or two arguments:
1040+
are autoprimed into closures of one or two arguments:
10341041

10351042
{ $^x - 1 }
10361043
{ '.' x $^y }
@@ -1094,14 +1101,14 @@ far as it makes sense, including outward through metaoperators. Hence:
10941101
(-*.abs)i # { (-$^x.abs)i }
10951102
@a «+» * # { @a «+» $^x }
10961103

1097-
=head3 The C<.assuming> Method
1104+
=head3 Operators with idiosyncratic Whatever
10981105

1099-
This is only for operators that are not C<Whatever>-aware. There is no requirement
1106+
The above is only for operators that are not C<Whatever>-aware. There is no requirement
11001107
that a C<Whatever>-aware operator return a C<WhateverCode> when C<Whatever>
11011108
is used as an argument; that's just the I<typical> behavior for functions
11021109
that have no intrinsic "globbish" meaning for C<*>. If you want to prime
11031110
one of these globbish operators, you'll need to write an explicit closure or do
1104-
an explicit prime on the operator with C<.assuming()>. Operators in
1111+
an explicit priming on the operator with C<.assuming()>. Operators in
11051112
this class, such as C<< infix:<..> >> and C<< infix:<xx> >>, typically I<do>
11061113
autoprime arguments of type C<WhateverCode> even though they do not
11071114
autoprime C<Whatever>, so we have:
@@ -2394,7 +2401,7 @@ Use of a signature that does not unambiguously select a single multi results in
23942401
failure.
23952402

23962403
It still just returns a C<Routine> object. A call may also be partially
2397-
applied by using the C<.assuming> method:
2404+
applied (primed) by using the C<.assuming> method:
23982405

23992406
&foo.assuming(1,2,3,:mice<blind>)
24002407

S06-routines.pod

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Synopsis 6: Subroutines
1616

1717
Created: 21 Mar 2003
1818

19-
Last Modified: 9 Jul 2011
20-
Version: 151
19+
Last Modified: 7 Oct 2011
20+
Version: 152
2121

2222
This document summarizes Apocalypse 6, which covers subroutines and the
2323
new type system.
@@ -2957,7 +2957,8 @@ block is being compiled, use the C<< COMPILING:: >> pseudopackage.]
29572957

29582958
=head2 Priming
29592959

2960-
Every C<Callable> object has a C<.assuming> method. This method does a partial
2960+
Every C<Callable> object has a C<.assuming> method, which does partial function application,
2961+
aka I<priming>. This method does a partial
29612962
binding of a set of arguments to a signature and returns a new function
29622963
that takes only the remaining arguments.
29632964

@@ -2969,7 +2970,7 @@ or equivalently:
29692970

29702971
or even:
29712972

2972-
&textfrom := &substr.assuming:str($text):len(Inf);
2973+
&textfrom := &substr.assuming :str($text):len(Inf);
29732974

29742975
It returns a C<Callable> object that implements the same behaviour
29752976
as the original subroutine, but has the values passed to C<.assuming>
@@ -2979,6 +2980,13 @@ already bound to the corresponding parameters:
29792980
$some = textfrom(50); # same as: $some = substr($text,50,Inf);
29802981
$last = textfrom(-1); # same as: $last = substr($text,-1,Inf);
29812982

2983+
Position parameters may also be primed. To skip a position argument,
2984+
pass a C<*>, which is handled specially by C<.assuming>. Passing a
2985+
C<Nil> causes priming with the default argument supplied with the
2986+
parameter at that position in the signature, or an undefined value if
2987+
the parameter in question has no default. C<Nil> may also be passed
2988+
to a named argument to force priming to the default.
2989+
29822990
The result of a C<use> statement is a (compile-time) object that also has
29832991
a C<.assuming> method, allowing the user to bind parameters in all the
29842992
module's subroutines/methods/etc. simultaneously:

0 commit comments

Comments
 (0)