Skip to content

Commit aeb66b4

Browse files
author
Jack Kuan
committed
Correct and clarify some parts of ruby-to-perl6 nutshell.
Also fixed the Dockerfile so that make docker-htmlify works. Specifically, I made it no longer purge the buildDeps because when npm install in highlights/, it needs build-essentials to compile some native module.
1 parent 7ebdcf6 commit aeb66b4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ RUN buildDeps=' \
2525
&& n=/usr/local/bin/n \
2626
&& curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n > "$n" \
2727
&& chmod +x "$n" \
28-
&& n stable \
29-
\
30-
&& apt-get purge --yes --auto-remove $buildDeps
28+
&& n stable
3129

3230
WORKDIR /perl6/doc
3331
EXPOSE 3000

doc/Language/rb-nutshell.pod6

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ sub f(&g:($)) {
311311
f(-> $n { say "Hi {$n}" }); # Explicit argument
312312
f -> $n { say "Hi {$n}" }; # Explicit argument, no parenthesis
313313
314-
# Additionally, if 'f' is a method on instance 'obj' you can use C<:>
314+
# Additionally, if 'f' is a method on instance 'obj' you can use ':'
315315
# instead of parenthesis
316316
my $obj; ...;
317317
$obj.f(-> $n { say "Hi {$n}" }); # Explicit argument
@@ -321,15 +321,28 @@ $obj.f: -> $n { say "Hi {$n}" }; # Explicit argument, no parenthesis
321321
=head3 C<*> Slurpy params / argument expansion
322322
323323
In Ruby you can declare an argument to slurp the remainder of the passed
324-
parameters into an array using a C<*> prefix. It works the same way in Perl 6:
324+
parameters into an array using a C<*> prefix. It works similarly in Perl 6:
325325
326326
=for code :lang<ruby>
327327
def foo(*args); puts "I got #{args.length} args!"; end # Ruby
328328
=for code
329329
sub foo(*@args) { say "I got #{@args.elems} args!" } # Perl 6
330330
331+
The Perl 6 version above is slightly different in that when it slurps in the
332+
arguments into @args, one level of nesting, if any, is automatically removed:
333+
334+
=for code
335+
sub foo(*@args) { dd @args }
336+
foo([1, [2, 3], 4], 5, [6, 7]); # [1, [2, 3], 4, 5, 6, 7]
337+
338+
To preserve the structure of the arguments, you can use C<**>:
339+
340+
=for code
341+
sub foo(**@args) { dd @args }
342+
foo([1, [2, 3], 4], 5, [6, 7]); # [[1, [2, 3], 4], 5, [6, 7]]
343+
331344
You might want to expand an array into a set of arguments. In Perl 6 this is
332-
also done using C<*>:
345+
done using a L<Slip|/type/Slip> C<|>:
333346
334347
=for code :lang<ruby>
335348
args = %w(a b c) # Ruby
@@ -338,7 +351,7 @@ foo(*args)
338351
=for code
339352
sub foo($q, $r, $s) { ... };
340353
my @args = <a b c>; # Perl 6
341-
foo(@*args);
354+
foo(|@args);
342355
343356
Perl 6 has many more advanced ways of passing parameters and receiving
344357
arguments, see L<Signatures|/language/functions#Signatures> and
@@ -355,7 +368,7 @@ $!foo # Private instance variable
355368
$.foo # Instance variable accessor
356369
$*foo # Dynamically scoped variable
357370
$^foo # A positional (placeholder) parameter to a block
358-
$:foo # A named parameter
371+
$:foo # A named (placeholder) parameter to a block
359372
$=foo # POD (documentation) variables
360373
$?FILE # Current source filename. The ? twigil indicates a compile-time value
361374
$~foo # Sublanguage seen by parser, uncommon

0 commit comments

Comments
 (0)