Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
some clarifications on whitespace requirements
  • Loading branch information
TimToady committed Feb 23, 2015
1 parent 1e44bb2 commit c6babf0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/Language/5to6.pod
Expand Up @@ -60,6 +60,8 @@ syntactic flexibility against the goal of having a consistent,
deterministic, extensible grammar that supports single-pass parsing and
helpful error messages, integrates features like custom operators cleanly,
and doesn't lead programmers to accidentally misstate their intent.
Also, the practice of "code golf" is slightly de-emphasized; Perl 6 is
designed to be more concise in concepts than in keystrokes.
As a result, there are various places in the syntax where whitespace is
optional in Perl 5, but is either mandatory or forbidden in Perl 6. Many of
Expand All @@ -74,38 +76,43 @@ I<No space allowed before the opening parenthesis of an argument list.>
substr ($s, 4, 1); # Perl 5 (in Perl 6 this would try to pass a single
# argument of type List to substr)
substr($s, 4, 1); # Perl 6
substr $s, 4, 1; # Perl 6 - alternative, parentheses-less style
substr $s, 4, 1; # Perl 6 - alternative parentheses-less style
=end item
=begin item
I<No space allowed before the opening bracket of an array/hash subscript, or around the method call operator.>
I<No space allowed before the opening bracket of a postcircumfix (such as an array/hash subscript), or around the method call operator.>
$people [0] -> name; # Perl 5
@people[0].name # Perl 6
@people.[0].name # Perl 6, alternative pseudo-method style
=end item
=begin item
I<No space allowed after a prefix (or before a postfix/postcircumfix)
operator.>
I<No space allowed before a postfix operator.>
$i ++; # Perl 5
$i++; # Perl 6
$i.++; # Perl 6, alternative pseudo-method style
=end item
=begin item
I<Space required after (before) an infix operator, if it would otherwise
conflict with an existing prefix (postfix/postcircumfix) operator.>
I<Space required before an infix operator if it would
conflict with an existing postfix/postcircumfix operator.>
$n<1; # Perl 5 (in Perl 6 this would conflict with postcircumfix < >)
$n < 1; # Perl 6
=end item
However, note that you can use L<unspace|http://design.perl6.org/S02.html#Unspaces>
to add whitespace in Perl 6 code in places where it is otherwise not
allowed:
# Perl 5
my @books = $xml->parse_file($file) # some comment
my @books = $xml->parse_file($file) # some comment
->findnodes("/library/book");
# Perl 6
Expand Down

0 comments on commit c6babf0

Please sign in to comment.