On Wed, Aug 23, 2006 at 06:20:55PM -0400, Mark Stosberg wrote:
: I noticed in pugs, 'ref' does not return 'HASH' and 'ARRAY' as Perl5
: does, but returns values including 'Hash', 'Array' and 'Array::Const'.

Well, first of all, ref is going away entirely, since there's no such
thing as a reference in Perl 6 (or everything is a reference, looking
at it the other way), so in a boolean context it would be trivially
true (or false) for everything.  Its use to return the type of the
referent is then completely misnamed.

And even for that use, returning a string is wrong.  It should return
the type itself, and that should stringify to the type name if you use
it in string context.  Which mostly you don't want to.

Anyway, .ref is likely to end up with a name like .what or .WHAT
instead.  (And .SKID is probably changing to .WHO or .WHICH at the
same time.  And maybe .META gets renamed .HOW while we're at it.
Maybe .WHERE gives you the memory address, or the url, or something.
As for .WHY, well, .WHYNOT? :-)

: I don't find meaningful mentions of 'HASH' and 'ARRAY' by grep'ing
: docs/Perl6 (or even "ref"!), so I wanted to check in here about the
: meaningfulness of this change.

It's meaningful.  There is no longer a distinction between fake types
naming internal forms and real types.  So we renamed the formerly fake
types to look more like real types, because they are.

: Personally, I dislike the change from HASH to 'Hash' because it seems to
:  be change without a significant benefit. It's annoyingly different.

Oh, if that's your smallest annoyance, please count yourself lucky.  :)

: The ARRAY case is worse, because it seems I now need to write this:
: 
:  if ref $a eq any('Array','Array::Const')  {

You're in P5-think here in assuming that type names are merely strings.
In P6-think you just want to treat the type as a first class object.  In
particular, smart match already does what you want and handles inheritance
for you.  Instead of saying

    if ref $a eq 'ARRAY' {

you really want:

    if $a ~~ Array {

and that also matches Array::Const, assuming it's derived from Array.

: If you are interested, here's code which illustrates cases when
: 'Array' is returned, versus 'Array::Const'
: 
:  my $a = [<a>];
:  my $b = \@('b');
: 
:  say ref $a;
:  say ref $b;
: 
: I'd like for 'HASH' and 'ARRAY' to keep working, or for the Perl6 docs
: to justify the change.

The justifications are mostly off in the Apocalypses.  Use of
types in smartmatching is mostly discussed in A04, for instance.
But the synopses are primarily intended contain just the changes,
not the rationale for the changes.

Larry

Reply via email to