On Wed, Jul 12, 2006 at 01:27:24PM -0500, Patrick R. Michaud wrote:
> The perl6 compiler has a custom string type, currently called
> "Perl6Str". What's the canonically correct mechanism for creating
> an object of that type?
>
> $P0 = new 'Perl6Str'
> $P0 = new .Perl6Str
> $P0 = new [ 'Perl6Str' ]
>
> At different stages of Parrot development I've seen different
> answers to this question, so it'd be helpful to know what's "correct".
Correct are all three, but:
1) and 3) are totally the same
(bracketed syntax just containing a single string constant just
yields that string concstant as a result)
thusly, 3) is containing some syntax overkill :-)
1) works always, but defers the type lookup to runtime. It's a
more efficient version of:
$I0 = find_type 'Perl6Str'
$P0 = new $I0
..., which takes one more opcode dispatch
2) only works, *if* the lib, which defines that type is already
loaded (via :immediate/loadlib or .loadlib), because it's
translated to new_p_ic, i.e. the type name is converted to
a type number at compile time, which speeds up run time
object creation.
A remark WRT:
$P0 = new Integer # bare word 'Integer'
this currently works with a lexer hack (and special code for 'new' IIRC)
but it's deprecated in favour of the much more explicit C<.Integer>,
which is indicating some macroish replacement.
> Pm
leo