develooper Front page | | Postings from August 2000

Re: RFC 148 (v1) Add reshape() for multi-dimensional array reshaping

Thread Previous
Nathan Torkington
August 25, 2000 15:37
Re: RFC 148 (v1) Add reshape() for multi-dimensional array reshaping
Message ID:
David L. Nicol writes:
> Looks like if we give the data type control over what
> the meaning of square brackets after it is, the rest
> becomes example code.  I think this s covered in the
> horribly misnamed which
> covers overloading bracketing.

The big problem with 115 is that it doesn't mention how to


where $foo is an array, from


where @foo is an array.

syntax doesn't suffer from this ambiguity, I believe.  I'm not hot on
it because it's new.  The curmudgeon in me believes that it should be
possible to do what you want to do with the current array subscript

Better, I think, would be a merging of tie() and overload() so
that you can make objects that act like Perl arrays.  But
$foo[EXPR] presently puts EXPR into scalar context.  But slices
with : would require the FETCH method to be called with all the
info in the slice.

(idea!) Unless : was shorthand for [] building.


is equivalent to

  [X, Y, Z]

Then your FETCH method would still be called with one argument, and []
processing for objectitied arrays wouldn't require specialized
processing of the [].

Some thoughts on what this would look like in a program:

  my PDL @foo;	# ties @foo to PDL?  Larry might have suggestions
		# for a syntax
  $foo[2] = 5;	# $object_behind_foo -> STORE(2, 5)

Then you'd get a slice by saying:

  @foo[2:5] = (9..12);
		# $object_behind_foo -> STORE( [2,5], 9,10,11,12 );

  $foo[2:5] = (9..12);
		# same thing.  If you didn't want it to be the
		# same thing, make the X:Y in list context actually
		# produce the list of values from X to Y

  my PDL @bar = @foo[2:5];
		# ties @bar, calls
		# $obj_bar->STORE([], $obj_foo->FETCH([2,5]))

		# $obj_foo->FETCH(2, [5..9])

So you know you have a multidim access because each dimension is
a different argument to FETCH.  Normal (one-dim) array accesess
result in single arguments to FETCH.

This doesn't let you have a simple list of indices in a single FETCH.
It doesn't distinguish between:


If you say the former is FETCH(2,5) then you lose the multidim.
nature where $foo[2][5] becomes FETCH(2,5).  Ugh.  I'm trying to do
this by adding as little new stuff as possible (e.g., lazy iterators,
$foo(...) syntax, etc.).

I think that at this point someone (I'm swamped right now) needs to go
and read up on how Python does the tie overloading merge.  Even a
pointer to online documentation would be good.  If they've already
solved these problems, we should see what they did.


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About