Home > Perl6 > On good terms with constants

On good terms with constants

While building a little helper module to fetch internet radio stations I found myself wanting to provide a constant named parameter. Quite a few methods of DateTime have a named argument when $*TZ would be wrong. As it turns out, this is really easy in Perl 6.

constant term:<GMT> = timezone => 0;
say DateTime.now(|GMT)

The term GMT is still a Pair so we have to slip it in but it’s still a bit shorter and more expressive once one gets used to the idea of constant Pair terms.

Categories: Perl6