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
# the following candidates match the type but require
399
+
# mutable arguments: ...
387
400
388
401
Instead of modifying the original value in place, use a routine or operator
389
402
that returns a new value:
@@ -394,7 +407,8 @@ that returns a new value:
394
407
See the documentation on L<containers|/language/containers> for more
395
408
information.
396
409
397
-
=head2What's up with array references and automatic dereferencing? Do I need the C<@> sigil?
410
+
=head2What's up with array references and automatic dereferencing?
411
+
Do I need the C<@> sigil?
398
412
399
413
In Perl 6, nearly everything is a reference, so talking about taking
400
414
references doesn't make much sense. Scalar variables can also contain
@@ -411,7 +425,6 @@ arrays directly:
411
425
The big difference is that arrays inside a scalar act as one value in list
412
426
context, whereas arrays will be happily iterated over.
413
427
414
-
=begincode
415
428
my @a = 1, 2, 3;
416
429
my $s = @a;
417
430
@@ -423,7 +436,6 @@ context, whereas arrays will be happily iterated over.
423
436
424
437
my @nested = flat $s, $s;
425
438
say @nested.elems; # OUTPUT: «2»
426
-
=endcode
427
439
428
440
You can force flattening with C<@( ... )> or by calling the C<.list> method
429
441
on an expression, and item context (not flattening) with C<$( ... )>
@@ -449,10 +461,8 @@ There are several reasons:
449
461
450
462
You likely tried to mix string interpolation and key characters, like HTML tags:
451
463
452
-
=begincode
453
464
my $foo = "abc";
454
465
say "$foo<html-tag>";
455
-
=endcode
456
466
457
467
Perl 6 thinks C<$foo> to be a Hash and C«<html-tag>» to be a string literal
458
468
hash key. Use a closure to help it to understand you.
@@ -480,7 +490,8 @@ routines that return lazy lists:
480
490
my @squares = (1..*).map(-> \x { x² });
481
491
=endcode
482
492
483
-
=head2Why can't I initialize private attributes from the new method, and how can I fix this?
493
+
=head2Why can't I initialize private attributes from the new method,
494
+
and how can I fix this?
484
495
485
496
Code like
486
497
@@ -541,9 +552,9 @@ nothing in that value except the type).
541
552
print $x; # empty string plus warning
542
553
say $x; # OUTPUT: «(Date)»
543
554
544
-
So, C<say> is optimized for debugging; display is optimized for people; and C<print>
545
-
and C<put> are most suitable for producing output for other programs
546
-
to consume.
555
+
So, C<say> is optimized for debugging; display is optimized for people;
556
+
and C<print> and C<put> are most suitable for producing output for other
557
+
programs to consume.
547
558
548
559
C<put> is thus sort of a hybrid between C<print> and C<say>;
549
560
like C<print>, its output is suitable for other programs,
@@ -573,20 +584,21 @@ C<die> throws an exception.
573
584
C<fail> returns a C<Failure> object. (If the caller has declared C<use fatal;>
574
585
in the calling lexical scope, C<fail> throws an exception instead of returning.)
575
586
576
-
A C<Failure> is an "unthrown" or "lazy" exception. It's an object that
577
-
contains the exception, and throws the exception if you try to use the C<Failure>
587
+
A C<Failure> is an "unthrown" or "lazy" exception. It's an object that contains
588
+
the exception, and throws the exception if you try to use the C<Failure>
578
589
as an ordinary object, or ignore it in sink context.
579
590
580
591
A C<Failure> returns C<False> from a C<defined> check, and you can extract
581
592
the exception with the C<exception> method.
582
593
583
-
=head2Why is C<wantarray> or C<want> gone? Can I return different things in different contexts?
594
+
=head2Why is C<wantarray> or C<want> gone?
595
+
Can I return different things in different contexts?
584
596
585
597
Perl 5 has the L<C<wantarray>|/language/5to6-perlfunc#wantarray> function that
586
598
tells you whether it's called in void, scalar or list context. Perl 6 has no
587
-
equivalent construct because context does not flow inwards; i.e., a routine would need
588
-
time travel to know which context it's called in because context is lazy (known
589
-
only when the results are used later).
599
+
equivalent construct because context does not flow inwards; i.e.,
600
+
a routine would need time travel to know which context it's called in because
601
+
context is lazy (known only when the results are used later).
590
602
591
603
For example, Perl 6 has multiple dispatch. So, in a code example like
592
604
@@ -765,17 +777,17 @@ them offer all.
765
777
766
778
=itemPerl 6's mottos remain the same as they have been for Perl all along: “Perl is different. In a nutshell, Perl is designed to make the easy jobs easy, without making the hard jobs impossible.” and “There Is More Than One Way To Do It”. Now with even more -Ofun added.
767
779
768
-
Please see theL<feature comparison
769
-
matrix|https://perl6.org/compilers/features> for an overview of implemented
0 commit comments