Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added a link to native types
Since most of the other related issues have been addressed, including
the early issue #1376, this closes #1879
  • Loading branch information
JJ committed Jul 9, 2018
1 parent fb29aa7 commit 493b1e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions doc/Language/functions.pod6
Expand Up @@ -63,7 +63,7 @@ By default, subroutines are L<lexically scoped|/syntax/my>. That is,
C<sub foo {...}> is the same as C<my sub foo {...}> and is only
defined within the current scope.
=begin code :allow<L>
=begin code
sub escape($str) {
# Puts a slash before non-alphanumeric characters
S:g[<-alpha -digit>] = "\\$/" given $str
Expand All @@ -84,7 +84,8 @@ say escape 'foo#bar?'; # OUTPUT: «foo\#bar\?␤»
say escape 'foo#bar?'; # OUTPUT: «foo\#bar\?␤»
=end code
Subroutines don't have to be named. If unnamed, they're called I<anonymous> subroutines.
Subroutines don't have to be named. If unnamed, they're called I<anonymous>
subroutines.
say sub ($a, $b) { $a ** 2 + $b ** 2 }(3, 4) # OUTPUT: «25␤»
Expand Down Expand Up @@ -853,7 +854,7 @@ a 1; # OUTPUT: «Int 1␤Any 2␤Back in Int with 5␤»
Here, C<a 1> calls the most specific C<Int> candidate first, and C<callwith>
re-dispatches to the less specific C<Any> candidate. Note that although our
parameter C<$x + 1> is an Int, still we call the next candidate in the chain.
parameter C<$x + 1> is an C<Int>, still we call the next candidate in the chain.
=head2 sub nextsame
Expand Down
4 changes: 3 additions & 1 deletion doc/Language/nativecall.pod6
Expand Up @@ -17,7 +17,7 @@ The simplest imaginable use of C<NativeCall> would look something like this:
The first line imports various traits and types. The next line looks like
a relatively ordinary Perl 6 sub declaration—with a twist. We use the
"native" trait in order to specify that the sub is actually defined in a
native library. The platform-specific extension (e.g., '.so' or '.dll'),
native library. The platform-specific extension (e.g., C<.so> or C<.dll>),
as well as any customary prefixes (e.g., 'lib') will be added for you.
The first time you call "some_argless_function", the "libsomething" will be
Expand All @@ -29,6 +29,8 @@ that you can do is just adding to this simple pattern of declaring a Perl 6 sub
naming it after the symbol you want to call and marking it with the "native"
trait.
You will also need to declare and use native types. Please check L<the native types page|/language/nativetypes> for more information.
=head1 Changing names
Sometimes you want the name of your Perl subroutine to be different from the
Expand Down

0 comments on commit 493b1e3

Please sign in to comment.