develooper Front page | perl.perl6.language.data | Postings from September 2000

Re: RFC 204 (v2) Arrays: Use list reference for multidimensional array access

Thread Previous | Thread Next
From:
Bart Lateur
Date:
September 21, 2000 08:19
Subject:
Re: RFC 204 (v2) Arrays: Use list reference for multidimensional array access
Message ID:
ne9kss0racftkimv3o7d040ijqm9o4otca@4ax.com
On 20 Sep 2000 04:06:02 -0000, Perl6 RFC Librarian wrote:

>Ilya Zakharevich brought up the issue of a potential problem with
>objects which use blessed list references as their internal structure,
>and their use as indices.  Given a Bignum class, which stores its
>(external) value internally as a list of integers, doing something
>like:
>
>my $bignum = Bignum->new(23) # stored internally as [ 2, 3 ]
>print $array[$bignum]; # should it print $array[23] or $array[[2,3]]?
>
>can be ambiguous.  I'm not so sure.  I think that $bignum is not
>legal, under Perl5, to be an array index, and that if it is going to
>be use so, it would need to be $array[$bugnum->value] anyway.

Hmm... the problem is, I think, that array references and ordinary
scalars are both scalars.

What would be the difference between

	$a[2]

and 
	
	$a[[2]]

anyway? Aren't these just the same?

If so, why not grab back into the old box, and get the syntax for
"multidimensional hashes" in perl4?

single dimension:	$hash{$item}

2 dimensions:		$hash{$item1, $item2}

Note that because of the '$' prefix, this cannot be confused with a
narray slice:

hash slice, not multidimensionanl hash:		@hash {$item1, îtem2}

So, the similar syntax for ordinary arrays would then be:

	$array[2, 3]

not	$array[[2, 2]]

Please feel free to corrct me if I'm wrong.

-- 
	Bart.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About