Wednesday, June 24, 2009

Perl 6 Questions and further information

This is following a recent Perl 6 seminar I gave.

Perl 5 style is still supported.

Named parameters go into %_
Unnamed parameters go into @_

Subroutines can be predefined with:
sub foo {…}

… is known as the "yadayadayada" operator.

Lexically scoped subroutines:
my sub mysub () is context { …}



Optional parameters: ? now comes after the parameter name.
sub mysub ($value, @harry, %ash, $opt?) {…} 


Named parameters: prefix is now : , instead of + and are optional unless they have a ! suffix.
sub named ($value, :@harry!, :%ash, :$other) {…}

...

named(42, other = 'fred', harry = @files);


Slurpy parameters, like perl 5 lists and arrays, are prefixed *

C style prototypes
Are not supported. It appears that when a subroutine is called before it is defined the parameter resolution still works correctly. However a runtime error is reported, not a compile time error (as it would with Perl 5 prototypes).

Dynamic types
These are called "traits". See Synopsis 12: Objects.

Zip operator
Has changed, it is now 'Z'. Behaviour with different length arrays has also changed between pugs and Rakudo, the result uses the shortest:


my @array = qw(The quick brown fox);
my @brray = qw(Now is the time for all);

my @all = @array Z @brray;
say @all.elems();
say @all[];

@all = @brray Z @array;
say @all.elems();
say @all[];

Gives:


8
TheNowquickisbrownthefoxtime
8
NowTheisquickthebrowntimefox




Important further change

When testing these changes in Rakudo I ran up against a change I had almost forgotten. When calling a subroutine, no whitespace is allowed between the sub name and the open parentheses. That slowed me up until I remembered. A backward step IMHO.

Tuesday, June 23, 2009

MySQL VARCHAR limits

A delegate recently queried the size limit on a VARCHAR field in MySQL. Our course documentation states a maximum of 255 characters: that is correct. For larger fields use TEXT.

Wednesday, June 17, 2009

Perl 6 Questions

I recently gave a short talk on Perl 6, and a number of questions arose. I will answer those questions as soon as I can, but unfortunately other fires need fighting right now.

One of the reasons for the delay is that the syntax for subroutines for Perl 6 has changed again, and in fact my slides are now out of date. That also means that pugs and Rakudo are incompatible in a major way - they have always been out of step to some extent.