Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revision and reflow, refs #2594
  • Loading branch information
JJ committed Jan 27, 2019
1 parent 7a63873 commit 8ef3a57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
32 changes: 18 additions & 14 deletions doc/Type/HyperWhatever.pod6
Expand Up @@ -10,30 +10,33 @@ C<HyperWhatever> is very similar in functionality to L<Whatever|/type/Whatever>.
difference lies in C<HyperWhatever> standing in for I<multiple> values, rather
than a single one.
=head1 STANDALONE TERM
=head1 Standalone term
Just like with L<Whatever|/type/Whatever>, if a L<HyperWhatever|/type/HyperWhatever> is used as a term on its own,
no currying is done and the L<HyperWhatever|/type/HyperWhatever> object will be used as-is:
Just like with L<Whatever|/type/Whatever>, if a
L<HyperWhatever|/type/HyperWhatever> is used as a term on its own, no currying
is done and the L<HyperWhatever|/type/HyperWhatever> object will be used as-is:
sub foo ($arg) { say $arg.^name }
foo **; # OUTPUT: «HyperWhatever␤»
You can choose to interpret such a value as standing for multiple values in
your own routines. In core, a L<HyperWhatever|/type/HyperWhatever> can be used with this meaning
when smartmatching with L<Lists|/type/List>:
You can choose to interpret such a value as standing for multiple values in your
own routines. In core, a L<HyperWhatever|/type/HyperWhatever> can be used with
this meaning when smartmatching with L<Lists|/type/List>:
say (1, 8) ~~ (1, **, 8); # OUTPUT: «True␤»
say (1, 2, 4, 5, 6, 7, 8) ~~ (1, **, 8); # OUTPUT: «True␤»
say (1, 2, 8, 9) ~~ (1, **, 8); # OUTPUT: «False␤»
Wherever a L<HyperWhatever|/type/HyperWhatever> appears in the list on the right-hand side means
any number of elements can fill that space in the list being smartmatched.
Wherever a L<HyperWhatever|/type/HyperWhatever> appears in the list on the
right-hand side means any number of elements can fill that space in the list
being smartmatched.
=head1 CURRYING
=head1 Currying
When it comes to currying, the L<HyperWhatever|/type/HyperWhatever> follows the same
rules as L<Whatever|/type/Whatever>. The only difference is L<HyperWhatever|/type/HyperWhatever> produces a
L<Callable|/type/Callable> with a L«C<*@> slurpy|/syntax/*@» as a signature:
When it comes to currying, the L<HyperWhatever|/type/HyperWhatever> follows the
same rules as L<Whatever|/type/Whatever>. The only difference is
L<HyperWhatever|/type/HyperWhatever> produces a L<Callable|/type/Callable> with
a L«C<*@> slurpy|/syntax/*@» as a signature:
say (**²)(1, 2, 3, 4, 5); # OUTPUT: «(1 4 9 16 25)␤»
Expand All @@ -44,8 +47,9 @@ that simply maps each element in the arguments over:
my &hyper-whatever = sub (*@args) { map *², @args }
say hyper-whatever(1, 2, 3, 4, 5); # OUTPUT: «(1 4 9 16 25)␤»
When currying, mixing L<HyperWhatever|/type/HyperWhatever> with L<Whatever|/type/Whatever> is not permitted.
When currying, mixing L<HyperWhatever|/type/HyperWhatever> with
L<Whatever|/type/Whatever> is not permitted.
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
17 changes: 9 additions & 8 deletions doc/Type/WhateverCode.pod6
Expand Up @@ -6,8 +6,8 @@
class WhateverCode is Code { }
C<WhateverCode> objects are the result of L<Whatever|/type/Whatever>-currying. See the
L<Whatever|/type/Whatever> documentation for details.
C<WhateverCode> objects are the result of L<Whatever|/type/Whatever>-currying.
See the L<Whatever|/type/Whatever> documentation for details.
When you wish to control how a method or function interprets any
I<Whatever stars>, you may use multi dispatch with C<Whatever> and
Expand Down Expand Up @@ -38,9 +38,10 @@ C<WhateverCode> parameters to do so, as in the following example:
say get-val($c, *); # OUTPUT: «2␤»
say get-val($c, *-1); # OUTPUT: «1␤»
The C<WhateverCode> C<does> L<Callable|/type/Callable> role, so it's possible to introspect
the type of C<Callable> it contains. Continuing the previous
example, we can add a multi that handles a C<WhateverCode> with two arguments:
The C<WhateverCode> C<does> the L<Callable|/type/Callable> role, so it should be
possible to introspect the type of C<Callable> it contains; for instance,
continuing the previous example, we can add a multi that handles a
C<WhateverCode> with two arguments via checking the signature:
=begin code :skip-test<compile time error>
# Define what to do with two * in an expression
Expand All @@ -61,8 +62,8 @@ say get-val($c, @a[*-1]) # 2, because the star belongs to the Array class
This can make the ownership of I<Whatever stars> become confusing rather
quickly, so be careful not to overdo it.
You may instead type-constrain using L<Callable|/type/Callable> type in order to accept
any C<Callable>, including C<WhateverCode>:
You may instead type-constrain using L<Callable|/type/Callable> type in order to
accept any C<Callable>, including C<WhateverCode>:
sub run-with-rand (Callable $code) { $code(rand) };
run-with-rand *.say; # OUTPUT: «0.773672071688484␤»
Expand All @@ -76,4 +77,4 @@ to type:
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 comments on commit 8ef3a57

Please sign in to comment.