On Tue, Nov 30, 2004 at 04:41:00AM +0300, Alexey Trofimenko wrote:
: >P.P.P.S. If answer on my "why?" would be "just because!" I would take it  
: >silently.
: 
: yes, answer was as I predicted above. I promised..

You have a funny idea of what "silently" means.  :-)

: ..but:
: >As far as I understood, arrays and hashes, and references them are much  
: >more similar in Perl6 than it was in Perl5.
: >
: >F.e. we have @a and $a = [EMAIL PROTECTED];
: >the same:
: >
: >     push @a,1,2,3   push $a, 1,2,3
: >     $b = @a         $b = $a
: >(?)  say "@a[]"      say "$a[]"
: >(?)  myfunc( [EMAIL PROTECTED])    myfunc ( *$a)
: >
: >...
: 
: were all thoose right?

I think so.

: >hm.. i'm not so competent to continue that list.. could anyone kind make  
: >a comparison table?
: 
: yes, please! I think, answer could be very informative for other readers  
: too. and even could make it's way to perl6 documentation. So, where's @a  
: and [EMAIL PROTECTED] are the same, and where they aren't?

I think the only place they differ is in list context.  @a always
interpolates, and $a never does.

: >in all other places where they work different, we could use @$a in place  
: >of @a, right?
: 
: if @ in @a is a part of name, would @$b work? and what's that @ here,  
: behind the scenes? operator? macro?

Syntactic sugar for $b[], basically.

By the way, I've always wondered about the possibility declaring things like

    my bit @$vector;

as a way of specify that @vector and $vector are the same object.
That would let you have your highlander variables when you want them,
without having to figure out whether &foo and $foo are the same.

: >...
: >P.P.P.P.S
: >  open $file, "filename";
: >  print @file;
: >...
: 
: ..er, in that case:
:    open $file, "filename";
:    print @$file;

In any case, the open function doesn't take a filehandle as its first
argument anymore.  It returns the new filehandle.

: i mean, what about using objects(files, iterators, etc) as arrays? AFAIK,  
: we will have custom subscripting defined on our objects, so $file[10]  
: could be made to work, but what about @$file, or @($file) or $file[] (um,  
: maybe $file[*], I forgot) would it make any sense?

Any object that mixes in the ArrayIndex role can be indexed as an array.
Any object that mixes in the HashIndex role can be indexed as a hash.
Though it's probable that any object will act like a hash if you force
it, in which case $obj{'key'} ends up trying to call $obj.key, just so
that people can write in the Perl 5 object attribute idiom, and have it
really using accessors underneath.  But we may yet decide that's a bad
idea as a default.  Maybe it's just turned on by the p5-to-p6 translator.

: and, one more question: if we would have both tying (arrays which call  
: hidden object methods) and objects which could act as array references,  
: where's a difference between them? could it be THE same? Should it? could  
: we write
:  my $a = new ArrayLikeClass;
:  my @b := @$a;
:    or
:  my @b := $a;
: (which one is right?)

I don't see a problem with either of them, but I didn't get enough sleep
last night, so I could be completely clueless.  In any event, we may
allow

    my @$a is ArrayLikeClass;

as a shorthand for the above.  Or at least it should be possible via pragma.

Larry

Reply via email to