Skip to content

Commit

Permalink
Reindexing Python stuff with category "Python"
Browse files Browse the repository at this point in the history
This closes #2355. It so happens you didn't need to special-code a new
category; as a matter of fact, there's a simple (if obscure) way of
doing it, which I have used. Also correcting some accidental indexing
somewhere else.
  • Loading branch information
JJ committed Oct 11, 2018
1 parent bf57d08 commit 39aed8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
3 changes: 2 additions & 1 deletion doc/Language/grammars.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ This comes in handy when you're already differentiating the proto regexes with
the strings you're going to match, as using C«<sym>» token prevents repetition
of those strings.
=head3 X«"Always succeed" assertion|<?>»
X<|<?>>
=head3 "Always succeed" assertion
The C«<?>» is the I<always succeed> assertion. When used as a grammar
token, it can be used to trigger an Action class method. In the following
Expand Down
35 changes: 16 additions & 19 deletions doc/Language/py-nutshell.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ Many of the other unicode operators work as you would expect
(exponents, fractions, π), but every unicode operator
or symbol that can be used in Perl 6 has an ASCII equivalent.
=head2 Control flow
=head2 X<Control flow|Python>
Python has C<for> loops and C<while> loops:
=for code :lang<python>
=for code :lang<Python>
for i in 1, 2:
print i
j = 1
Expand Down Expand Up @@ -346,7 +346,7 @@ Perl 6
}
=head2 Lambdas, functions and subroutines
=head2 X<Lambdas, functions and subroutines|Python>
Declaring a function (subroutine) with C<def> in Python is accomplished
with C<sub> in Perl 6.
Expand Down Expand Up @@ -452,9 +452,10 @@ i.e. these are the same:
my $power = { $^x ** $^y };
my $power = -> $x, $y { $x ** $y };
=head2 List comprehensions
=head2 X<List comprehensions|Python>
Postfix statement modifiers and blocks can be combined to make list comprehensions.
Postfix statement modifiers and blocks can be combined to make list
comprehensions.
Python
Expand Down Expand Up @@ -491,9 +492,10 @@ becomes either of these:
Using C<map> (which is just like Python's C<map>) and
C<grep> (which is like Python's C<filter>) is an alternative.
=head2 Classes and objects
=head2 X<Classes and objects|Python>
Here's an example from the Python L<docs|https://docs.python.org/3/tutorial/classes.html#class-and-instance-variables>.
Here's an example from the Python
L<docs|https://docs.python.org/3/tutorial/classes.html#class-and-instance-variables>.
First, "instance variables", aka attributes in Perl 6:
Python:
Expand All @@ -512,7 +514,7 @@ Perl 6:
Constructors by default take named arguments in Perl 6,
and use the method C<new>.
Python
Python:
=for code :lang<python>
d = Dog('Fido')
Expand Down Expand Up @@ -633,9 +635,7 @@ or
...
}
=head2 Decorators
X<|Decorators (Python)>
X<|@decorator (Python)>
=head2 X<Decorators|Python>
Decorators in Python are a way of wrapping a function
in another one. In Perl 6, this is done with C<wrap>.
Expand Down Expand Up @@ -685,15 +685,13 @@ An alternative would be to use a trait:
world;
=head2 Context managers
X<|Context Managers (Python)>
X<|with (Python)>
=head2 X<Context managers|Python>
Context managers in Python declare actions that happen when entering
or exiting a scope.
Here's a python context manager that prints the strings
'hello', 'world', and 'bye':
Here's a Python context manager that prints the strings
'hello', 'world', and 'bye'.
=begin code :lang<python>
class hello:
Expand All @@ -706,7 +704,7 @@ with hello():
print 'world'
=end code
For enter and exit events, passing a block as
For "enter" and "exit" events, passing a block as
an argument would be one option:
sub hello(Block $b) {
Expand All @@ -728,8 +726,7 @@ run on entering or leaving a block.
say 'world';
}
X<|input (Python)>
=head2 Input
=head2 X<C<input>|Python>
In Python 3, the C<input> keyword is used to prompt the user:
Expand Down

0 comments on commit 39aed8d

Please sign in to comment.