Skip to content

Commit ec806e6

Browse files
committed
Update Language/faq.pod6
1 parent d82dc3c commit ec806e6

File tree

1 file changed

+86
-74
lines changed

1 file changed

+86
-74
lines changed

doc/Language/faq.pod6

Lines changed: 86 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ logs|https://www.google.com/search?q=site:irclog.perlgeek.de+inurl:perl6>.
9696
=head2 What is the Perl 6 specification?
9797
9898
The specification refers to the official test suite for Perl 6. It's called
99-
roast and is L<hosted on github|https://github.com/perl6/roast>. Any compiler
99+
L<roast|https://github.com/perl6/roast> and is hosted on github. Any compiler
100100
that passes the tests is deemed to implement that version of the Perl 6
101101
specification.
102102
@@ -116,33 +116,36 @@ Yes, see L<glossary|/language/glossary>.
116116
117117
=head2 I'm a Perl 5 programmer. Where is a list of differences between Perl 5 and Perl 6?
118118
119-
There are several C<5to6-> guides in the L<Language section of the
119+
There are several B<5to6-> guides in the L<Language section of the
120120
documentation|https://docs.perl6.org/language.html>, most notable of which
121-
is the L<5to6-nutshell guide|https://docs.perl6.org/language/5to6-nutshell>.
121+
is the L<5to6-nutshell|https://docs.perl6.org/language/5to6-nutshell> guide.
122122
123123
=head2 I'm a Ruby programmer looking for quickstart type docs?
124124
X<|Ruby (FAQ)>
125125
126-
See the 'rb-nutshell' pod under L<https://docs.perl6.org/language/rb-nutshell>
126+
See the L<rb-nutshell|https://docs.perl6.org/language/rb-nutshell> guide.
127127
128128
=head1 Modules
129129
130130
=head2 Is there a CPAN (repository of third party library modules) for Perl 6?
131131
X<|CPAN (FAQ)>X<|ecosystem>
132132
133-
Yes, it's the same L<CPAN|http://cpan.org/> as for Perl 5! The only difference is
134-
when using L<PAUSE|http://pause.perl.org/> to upload the module, you'd select
133+
Yes, it's the same L<CPAN|http://cpan.org/> as for Perl 5! The only difference
134+
is when using L<PAUSE|http://pause.perl.org/> to upload the module, you'd select
135135
C<Perl 6> as the target directory. The
136-
L«C<App::Mi6> tool|https://modules.perl6.org/l/App::Mi6» can simplify the uploading
137-
process. Latest versions of L«C<zef> module installer|https://modules.perl6.org/l/zef»
136+
L«C<App::Mi6> tool|https://modules.perl6.org/l/App::Mi6» can simplify the
137+
uploading process. Latest versions of
138+
L«C<zef> module installer|https://modules.perl6.org/l/zef»
138139
automatically check for latest versions of a module on CPAN as well as our
139140
L<GitHub-based ecosystem|https://github.com/perl6/ecosystem/>.
140141
141142
Viewing of modules available CPAN will be implemented soon on
142143
L<modules.perl6.org website|https://modules.perl6.org/> (temporarily, it's
143-
available as L<a raw JSON file|https://github.com/ugexe/Perl6-ecosystems/blob/master/cpan.json>
144+
available as a
145+
L<raw JSON file|https://github.com/ugexe/Perl6-ecosystems/blob/master/cpan.json>
144146
145147
=head2 Is there a perldoc (command line documentation viewer) for Perl 6?
148+
X<|p6doc (FAQ)>
146149
147150
Yes, it's called p6doc and is present in the ecosystem under that name. It's
148151
present in Rakudo Star but you will need to install it using the monthly
@@ -157,12 +160,13 @@ well with most Perl 5 modules. It can even run Perl 5 Catalyst and DBI.
157160
=head2 Can I use C and C++ from Perl 6?
158161
X<|C and C++ (FAQ)>
159162
160-
L<Nativecall|https://docs.perl6.org/language/nativecall> makes this particularly easy.
163+
L<Nativecall|https://docs.perl6.org/language/nativecall> makes this
164+
particularly easy.
161165
162166
=head2 Nativecall can't find libfoo.so and I only have libfoo.so.1.2!
163167
164-
This is commonly seen on Debian-like systems. You need to install C<libfoo-dev> package,
165-
to set a sym link for the missing file.
168+
This is commonly seen on Debian-like systems. You need to install C<libfoo-dev>
169+
package, to set a sym link for the missing file.
166170
167171
=head2 Where have all the traditional UNIX library functions gone?
168172
X<|UNIX library functions (FAQ)>
@@ -183,16 +187,17 @@ basic modules|https://docs.perl6.org/language/modules-core>.
183187
184188
Many more modules can be found in the L<ecosystem|http://modules.perl6.org/>.
185189
186-
=head2 Is there something like B::Deparse/How can I get hold of the AST?
190+
=head2 Is there something like C<B::Deparse>/How can I get hold of the AST?
187191
188-
Use C<--target=optimize> command line option to view the AST of your program; e.g.:
189-
C<perl6 --target=optimize -e 'say "hi"'>
192+
Use C<--target=optimize> command line option to view the AST of your program,
193+
e.g., C<perl6 --target=optimize -e 'say "hi"'>
190194
191-
The C<optimize> target gives the AST after the static optimizer did its job, while
192-
target C<ast> gives the AST before that step. To get the full list of available targets,
193-
run C<perl6 --stagestats -e "">
195+
The target C<optimize> gives the AST after the static optimizer did its job,
196+
while target C<ast> gives the AST before that step. To get the full list of
197+
available targets, run C<perl6 --stagestats -e "">
194198
195199
=head2 What is Precompilation?
200+
X<|Precompile (FAQ)>
196201
197202
When you load a module for the first time, Rakudo compiles it into bytecode,
198203
and both stores it on disk, and uses the compiled bytecode. On subsequent
@@ -201,17 +206,18 @@ significantly faster.
201206
202207
=head1 Language Features
203208
204-
=head2 How can I dump Perl 6 data structures (like Perl 5 Data::Dumper and similar)?
209+
=head2 How can I dump Perl 6 data structures
210+
(like Perl 5 Data::Dumper and similar)?
205211
X<|Data::Dumper (FAQ)>
206212
207213
Typical options are to use L<say> routine that uses L<gist> method that
208214
gives the "gist" of the object being dumped. More detailed output can be
209215
obtained by calling L<perl> method that typically returns representation
210216
in L<EVAL|/routine/EVAL>-able code.
211217
212-
If you're using the L<rakudo implementation|http://rakudo.org>, you can use
213-
the L«non-standard C<dd> routine|/programs/01-debugging#Dumper_function_dd»
214-
for dumping, whose output is similar to L<perl>, but with more information.
218+
If you're using the L<rakudo|http://rakudo.org> implementation, you can use
219+
the L«rakudo-specific C<dd> routine|/programs/01-debugging#Dumper_function_dd»
220+
for dumping, whose output is similar to L<.perl>, but with more information.
215221
216222
Examples:
217223
@@ -255,11 +261,12 @@ Example:
255261
256262
=head2 What is C<(Any)>?
257263
258-
L<Any|/type/Any> is a top level class most objects inherit from. The L<Any> type object is L<the
259-
default value|/type/Attribute#index-entry-trait_is_default_%28Attribute%29-Trait_is_default>
260-
on variables and parameters without an explicit type constraint, which means you'll
261-
likely see C<(Any)> printed when you output a L<gist> of a variable without any value,
262-
such as using L«C<say> routine|/routine/say»:
264+
L«C<Any>|/type/Any» is a top level class most objects inherit from.
265+
The C<Any> type object is
266+
L<the default value|/type/Attribute.html#Trait_is_default> on variables and
267+
parameters without an explicit type constraint, which means you'll
268+
likely see C<(Any)> printed when you output a L<gist|/routine/gist> of
269+
a variable without any value, such as using L«C<say> routine|/routine/say»:
263270
264271
=begin code
265272
my $foo;
@@ -272,11 +279,12 @@ my $bar = 70;
272279
say $bar; # OUTPUT: «70␤»
273280
=end code
274281
275-
To test whether a variable has any defined values, see L<DEFINITE> and L<defined>
282+
To test whether a variable has any defined values, see
283+
L<DEFINITE|/classtut#index-entry-DEFINITE> and L<defined>
276284
routines. Several other constructs exist that test for definiteness, such as
277-
L«C<with>, C<orwith>, and C<without>|/syntax/with%20orwith%20without» statements,
278-
L«C<//>|/routine/$SOLIDUS$SOLIDUS», L<andthen>, L<notandthen>, and L<orelse> operators,
279-
as well as L<type constraint smileys|/type/Signature#Constraining_Defined_and_Undefined_Values>.
285+
L«C<with>, C<orwith>, and C<without>|/syntax/with%20orwith%20without»
286+
statements, L«C<//>|/routine/$SOLIDUS$SOLIDUS», L<andthen>, L<notandthen>, and
287+
L<orelse> operators, as well as L<type constraint smileys|/type/Signature#Constraining_Defined_and_Undefined_Values>.
280288
281289
=head2 What is C<so>?
282290
@@ -290,8 +298,7 @@ Example usage:
290298
say so 1|2 == 2; # OUTPUT: «True␤»
291299
292300
In this example, the result of the comparison (which is a
293-
L<Junction|/type/Junction>), is
294-
converted to Bool before being printed.
301+
L<Junction|/type/Junction>), is converted to Bool before being printed.
295302
296303
=head2 What are those C<:D> and C<:U> things in signatures?
297304
@@ -305,38 +312,39 @@ For example, if you declare a variable
305312
then not only can you assign integers (that is, instances of class Int) to it,
306313
but the C<Int> type object itself:
307314
308-
=for code :preamble<my Int $x>
309-
$x = Int
315+
=begin code :preamble<my Int $x>
316+
$x = Int
317+
=end code
310318
311319
If you want to exclude type objects, you can append the C<:D> type smiley,
312320
which stands for "definite":
313321
314322
=begin code
315323
my Int:D $x = 42;
316-
$x = Int; # dies with:
317-
# Type check failed in assignment to $x;
318-
# expected Int:D but got Int
324+
$x = Int;
325+
326+
# dies with:
327+
# Type check failed in assignment to $x;
328+
# expected Int:D but got Int
319329
=end code
320330
321331
Likewise, C<:U> constrains to undefined values, that is, type objects.
322332
323333
To explicitly allow either type objects or instances, you can use C<:_>.
324334
325-
=head2 What is the C<< --> >> thing in the signature?
335+
=head2 What is the C«-->» thing in the signature?
326336
327337
L«-->|/type/Signature#Constraining_Return_Types» is a return constraint, either
328338
a type or a definite value.
329339
330340
Example of a type constraint:
331341
332-
=begin code
333342
sub divide-to-int( Int $a, Int $b --> Int ) {
334343
return ($a / $b).narrow;
335344
}
336345
337346
divide-to-int(3, 2)
338347
# Type check failed for return value; expected Int but got Rat
339-
=end code
340348
341349
Example of a definite return value:
342350
@@ -366,24 +374,29 @@ If you want to do it anyway, you can abuse autothreading for that:
366374
say eigenstates(1|2|3).join(', ');
367375
# prints 1, 2, 3 or a permutation thereof
368376
369-
=head2 If Str is immutable, how does C<s///> work? If Int is immutable, how does C<$i++> work?
377+
=head2 If Str is immutable, how does C<s///> work? If Int is immutable,
378+
how does C<$i++> work?
370379
371-
In Perl 6, values of many basic types are immutable, but the variables holding them are
372-
not. The C<s///> operator works on a variable, into which it puts a newly
373-
created string object. Likewise, C<$i++> works on the C<$i> variable, not
380+
In Perl 6, values of many basic types are immutable, but the variables holding
381+
them are not. The C<s///> operator works on a variable, into which it puts a
382+
newly created string object. Likewise, C<$i++> works on the C<$i> variable, not
374383
just on the value in it.
375384
376385
Knowing this, you would not try to change a literal string (e.g. like
377-
C<'hello' ~~ s/h/H/;>), but you might accidentally do
378-
something equivalent using `map`:
386+
C<'hello' ~~ s/h/H/;>), but you might accidentally do something equivalent
387+
using C<map> as follows.
388+
389+
my @foo = <hello world>.map: { s/h/H/ };
379390
380-
my @foo = <hello world>.map: { s/h/H/ }; # dies with
381-
# Cannot modify an immutable Str (hello)
391+
# dies with
392+
# Cannot modify an immutable Str (hello)
382393
383-
my @bar = <hello world>».subst-mutate: 'h', 'H'; # dies with
384-
# Cannot resolve caller subst-mutate(Str: Str, Str);
385-
# the following candidates match the type but require
386-
# mutable arguments: ...
394+
my @bar = <hello world>».subst-mutate: 'h', 'H';
395+
396+
# dies with
397+
# Cannot resolve caller subst-mutate(Str: Str, Str);
398+
# the following candidates match the type but require
399+
# mutable arguments: ...
387400
388401
Instead of modifying the original value in place, use a routine or operator
389402
that returns a new value:
@@ -394,7 +407,8 @@ that returns a new value:
394407
See the documentation on L<containers|/language/containers> for more
395408
information.
396409
397-
=head2 What's up with array references and automatic dereferencing? Do I need the C<@> sigil?
410+
=head2 What's up with array references and automatic dereferencing?
411+
Do I need the C<@> sigil?
398412
399413
In Perl 6, nearly everything is a reference, so talking about taking
400414
references doesn't make much sense. Scalar variables can also contain
@@ -411,7 +425,6 @@ arrays directly:
411425
The big difference is that arrays inside a scalar act as one value in list
412426
context, whereas arrays will be happily iterated over.
413427
414-
=begin code
415428
my @a = 1, 2, 3;
416429
my $s = @a;
417430
@@ -423,7 +436,6 @@ context, whereas arrays will be happily iterated over.
423436
424437
my @nested = flat $s, $s;
425438
say @nested.elems; # OUTPUT: «2␤»
426-
=end code
427439
428440
You can force flattening with C<@( ... )> or by calling the C<.list> method
429441
on an expression, and item context (not flattening) with C<$( ... )>
@@ -449,10 +461,8 @@ There are several reasons:
449461
450462
You likely tried to mix string interpolation and key characters, like HTML tags:
451463
452-
=begin code
453464
my $foo = "abc";
454465
say "$foo<html-tag>";
455-
=end code
456466
457467
Perl 6 thinks C<$foo> to be a Hash and C«<html-tag>» to be a string literal
458468
hash key. Use a closure to help it to understand you.
@@ -480,7 +490,8 @@ routines that return lazy lists:
480490
my @squares = (1..*).map(-> \x { x² });
481491
=end code
482492
483-
=head2 Why can't I initialize private attributes from the new method, and how can I fix this?
493+
=head2 Why can't I initialize private attributes from the new method,
494+
and how can I fix this?
484495
485496
Code like
486497
@@ -541,9 +552,9 @@ nothing in that value except the type).
541552
print $x; # empty string plus warning
542553
say $x; # OUTPUT: «(Date)␤»
543554
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.
547558
548559
C<put> is thus sort of a hybrid between C<print> and C<say>;
549560
like C<print>, its output is suitable for other programs,
@@ -573,20 +584,21 @@ C<die> throws an exception.
573584
C<fail> returns a C<Failure> object. (If the caller has declared C<use fatal;>
574585
in the calling lexical scope, C<fail> throws an exception instead of returning.)
575586
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>
578589
as an ordinary object, or ignore it in sink context.
579590
580591
A C<Failure> returns C<False> from a C<defined> check, and you can extract
581592
the exception with the C<exception> method.
582593
583-
=head2 Why is C<wantarray> or C<want> gone? Can I return different things in different contexts?
594+
=head2 Why is C<wantarray> or C<want> gone?
595+
Can I return different things in different contexts?
584596
585597
Perl 5 has the L<C<wantarray>|/language/5to6-perlfunc#wantarray> function that
586598
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).
590602
591603
For example, Perl 6 has multiple dispatch. So, in a code example like
592604
@@ -765,17 +777,17 @@ them offer all.
765777
766778
=item Perl 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.
767779
768-
Please see the L<feature comparison
769-
matrix|https://perl6.org/compilers/features> for an overview of implemented
770-
features.
780+
Please see the
781+
L<feature comparison matrix|https://perl6.org/compilers/features>
782+
for an overview of implemented features.
771783
772784
=head2 Is Perl 6 fast enough for me?
773785
774786
That depends on what you are doing. Rakudo has been developed with the
775787
philosophy of "make it work right then make it work fast". It's fast for some
776-
things already but needs work for others.
777-
Since Perl 6 provides lots of clues to the JIT that other dynamic languages don't, we think
778-
we'll have a lot of headroom for performance improvements.
788+
things already but needs work for others. Since Perl 6 provides lots of clues
789+
to the JIT that other dynamic languages don't, we think we'll have a lot of
790+
headroom for performance improvements.
779791
780792
The following crude benchmarks, with all the usual caveats about such things,
781793
show that Perl 6 can be faster than Perl 5 for similar tasks if

0 commit comments

Comments
 (0)