@@ -287,11 +287,13 @@ There are several reasons:
287
287
288
288
= item they make it easy to interpolate variables into strings
289
289
290
- = item they form micro-namespaces for different variables, thus avoiding name clashes
290
+ = item they form micro-namespaces for different variables and twigils , thus avoiding name clashes
291
291
292
292
= item they allow easy single/plural distinction
293
293
294
- = item many natural languages use mandatory noun markers, so our brains are built to handle it
294
+ = item they work like natural languages that use mandatory noun markers, so our brains are built to handle it
295
+
296
+ = item they aren't mandatory, since you can declare sigilless names (if you don't mind the ambiguity)
295
297
296
298
297
299
= head2 Does Perl 6 have coroutines? What about C < yield > ?
@@ -309,7 +311,7 @@ routines that return lazy lists:
309
311
310
312
# second method, use .map or similar method
311
313
# on a lazy list
312
- my @squares = (1..*).map(-> $ x { $x * $x });
314
+ my @squares = (1..*).map(-> \ x { x² });
313
315
314
316
= head2 Why can't I initialize private attributes from the new method, and how can I fix this?
315
317
@@ -345,6 +347,10 @@ for more details) with all the named arguments that the user passes to the
345
347
constructor. C < :$!x > is a named parameter with name C < x > , and when called
346
348
with a named argument of name C < x > , its value is bound to the attribute C < $!x > .
347
349
350
+ But don't do that. If the name is public, there is no downside to
351
+ declaring it that way with C < $.x > since the external view is readonly
352
+ by default, and you can still access it internally with C < $!x > .
353
+
348
354
= head2 How and why do C < say > and C < print > differ?
349
355
350
356
The most obvious difference is that C < say > appends a newline at the
@@ -370,6 +376,7 @@ nothing in that value except the type).
370
376
371
377
So C < say > is optimized for debugging and display to people, C < print >
372
378
is more suitable for producing output for other programs to consume.
379
+ (Use C < put > if you want C < print > semantics with a newline.)
373
380
374
381
= head2 What's the difference between C < token > and C < rule > ?
375
382
@@ -392,15 +399,15 @@ C<regex> declares a plain regex without any implied modifiers.
392
399
393
400
C < die > throws an exception.
394
401
395
- If C < use fatal; > (which is dynamically scoped) is in scope, C < fail > also
396
- throws an exception. Otherwise it returns a C < Failure > from the routine
397
- it is called from.
402
+ C < fail > returns a C < Failure > object. (If the caller has declared C < use fatal; >
403
+ in the calling lexical scope, C < fail > instead throws an exception
404
+ instead of returning.)
398
405
399
- A C < Failure > is an "unthrown" or "soft " exception. It is an object that
400
- contains the exception, and throws the exception when the Failure is used
401
- as an ordinary object.
406
+ A C < Failure > is an "unthrown" or "lazy " exception. It is an object that
407
+ contains the exception, and throws the exception if you try to use the C < Failure >
408
+ as an ordinary object, or ignore it in sink context .
402
409
403
- A Failure returns False from a C < defined > check, and you can extract
410
+ A C < Failure > returns C < False > from a C < defined > check, and you can extract
404
411
the exception with the C < exception > method.
405
412
406
413
= head2 Why is C < wantarray > or C < want > gone? Can I return different things in different contexts?
0 commit comments