Little convenience tricks that people may have tried before in other languages, wondering if it would work, got disappointed 'cause it didn't, and moved on... But now in Perl 6 it does work!
- chaining comparison operators:
if $min <= $x <= $max { ... }
- short-circuiting ops returing original arg rather than True/False:
.say for @items || 'none'
- allowing self-reference in variable declarations
- ...
- prompting for lines from STDIN
- reading individual characters from STDIN for more complex interactive use-cases
- reacting to signals (think CTRL+C)
- brining timers/concurrency into the mix (e.g. for an animated ASCII progress bar) --> showcase a practical demo script?
The reasons behind syntax changes (or lack thereof) compared to Perl 5, that newbies might find curious or be sceptical about ("NIH syndrome!") before they understand the motivations behind them:
- new notation for regexes (see old blog post by Larry)
- new notation for the conditional ternary operator (see http://irclog.perlgeek.de/perl6/2014-10-28#i_9577215)
- keeping Perl sigils (see http://faq.perl6.org/#sigils)
- making sigils invariant
- ...
Briefly showcase a number of rosettacode.org tasks where the Perl 6 solution is particularly elegant or interesting.
...a.k.a. less special syntax & magic.
Many things that were 'magical' or 'special-cased' in Perl 5 now nicely fall out from cleaner, more generic rules - for example:
-
In P5, built-in listops like
map
were special, and could only be imperfectly mimicked using subroutine prototypes; In P6, all listops (built-in and custom) are parsed the same way, and some syntax has been cleaned up (e.g.{...}
instead ofsub {...}
) to always make them look elegant. -
P5 hard-coded the use of "localized global"
$_
,$a
,$b
variables formap
/sort
blocks; P6 has a clean mechanism for defining implicit subroutine signatures that can be used with any code block. -
P5 parses indexing of (and assignment to) array/hash elements as special syntax; In P6,
[ ]
and{ }
are normal postcircumfix operators that happen to potentially return lvalues (Scalar containers / proxy objects). -
In P5, all operators are hard-coded syntax; P6 allows you to treat operators as normal routines (e.g. get the function object with
&[+]
), and define your own ones. -
P6 supports lone
.foo
, instead of arbitrarily letting some routines (but not others) operate on$_
by default. -
Fewer magic variables.
-
P6 implements loop control (e.g.
next
) using control exceptions, thus making it available formap
and potentially also custom routines. -
...probably many more examples to be found!...