You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Language/py-nutshell.pod6
+13-4Lines changed: 13 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,14 +171,23 @@ Perl 6
171
171
say x;
172
172
# x is 10
173
173
174
-
Lambdas in Python can be written as pointy blocks in Perl 6.
174
+
Lambdas in Python are equivalent to anonymous subroutines in Perl 6.
175
+
One way to write them is as pointy blocks.
175
176
176
177
Python
177
-
l = lambda i: i * n
178
+
l = lambda i: i + 12
178
179
Perl 6
179
-
$l = -> $i { $i * $n }
180
+
$l = -> $i { $i + 12 }
180
181
181
-
Pointy blocks (like all blocks) have their own scope.
182
+
Another Perl 6 idiom for constructing lambdas is the Whatever code, C<*>.
183
+
A C<*> can be used in an expression to indicate that the expression is a
184
+
block, and that the C<*> should be replaced by the first parameter to
185
+
the block.
186
+
187
+
Perl 6
188
+
$l = * + 12
189
+
190
+
See the section below for more constructs.
182
191
183
192
Another example (from the Python L<FAQ|https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result>):
0 commit comments