Skip to content

Instantly share code, notes, and snippets.

@smls
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smls/116c4e55de020e17829a to your computer and use it in GitHub Desktop.
Save smls/116c4e55de020e17829a to your computer and use it in GitHub Desktop.

Ideas for 2014 Perl 6 advent calendar posts

The Little Things

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
  • ...

Writing interactive command-line apps

  • 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?

Justifications

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:

Best of Rosettacode

Briefly showcase a number of rosettacode.org tasks where the Perl 6 solution is particularly elegant or interesting.

Language Consistency & Correctness

...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 of sub {...}) to always make them look elegant.

  • P5 hard-coded the use of "localized global" $_, $a, $b variables for map/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 for map and potentially also custom routines.

  • ...probably many more examples to be found!...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment