perl6-language
[Top] [All Lists]

Re: Differential Subscripts

To: "John M. Dlugosz" <dhcgnd702@sneakemail.com>
Subject: Re: Differential Subscripts
From: "Jon Lang" <dataweaver@gmail.com>
Date: Fri, 8 Aug 2008 20:28:46 -0700
Cc: perl6-language@perl.org
Delivered-to: mailing list perl6-all@perl.org
Delivered-to: perl6-all-poster@perl.org
Delivered-to: mailing list perl6-language@perl.org
Delivered-to: perl6-language@perl.org
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=hU9ZWeZn4Ud8ulfNI/Mh65uaERlbJGjIaz/6PHN22g8=; b=IKeCNZDhoGb6/6XCOT3NGxjB5BGtR33mTOb5w39PTccwt8l2IIqNn5IN5IMhoEekwP BxV2QO1V6kGzH1xra8wEMriMDhMXcNmL/DYL0XRlqF+z6ed0zrUxJBJkLHl73lWKnLc6 7eUwoW7gNUCNoUc/pm57pJQNefIDXwUvh/qR4=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=nvbLXzeCxCgmoV/OG4PnhREG2VzJ0qbQGoD00wGuOYkuL9/dEEeBlBQ9MdIkcROKKr qkpxxWSAU+cmNZz8TA1vSGD6hNgMYFy2vo57i7g/6MP2xjVlUMkeVL24lBVT+7hJ7+NB C2q3vlSAczfa+XD1I+Rq6sP5u71lcDxt6eGY4=
In-reply-to: <22366-04544@sneakemail.com>
List-help: <mailto:perl6-all-help@perl.org>
List-id: <perl6-all.perl.org>
List-id: <perl6-language.perl.org>
List-post: <mailto:perl6-all@perl.org>
List-subscribe: <mailto:perl6-all-subscribe@perl.org>
List-unsubscribe: <mailto:perl6-all-unsubscribe@perl.org>
Mailing-list: contact perl6-all-help@perl.org; run by ezmlm
References: <22366-04544@sneakemail.com>
On Fri, Aug 8, 2008 at 7:41 PM, John M. Dlugosz
<dhcgnd702@sneakemail.com> wrote:
> How is @array[*-2] supposed to be implemented?
>
> S09<v28>
> // reported again 8-Aug-2008
>
> Is this magic known to the parser at a low level, or is it possible to
> define your own postcircumfix operators that interact with the
> interpretation of the argument?

IMHO, this can best be answered by the implementors: it depends on how
difficult it would be to enable user-defined code.  My own bias would
be toward the latter; but I'm not an implementor.

> Does this use of * apply to any user-defined postcurcumfix:<[ ]> or just
> those defining the function for the Positional role, or what?  And whether
> or not it always works or is particular to the built-in Array class, we need
> to define preciely what the * calls on the object, because I<those> may be
> overridden. For example, it is obvious that a lone * in an expression calls
> .length.  But the *{$idx} and *[$idx] work by calling some method on the
> Array object, right?  Something like @array.user_defined_index<May> to
> discover that May maps to 5, or @array.user_defined_index[5] to produce May.
>  That is, the accessor .user_defined_index() returns an object that supports
> [] and {} just like an Array.  It may or might not be an Array populated
> with the inverse mappings. But it behaves that way.
>
> But that doesn't work for multidimensional arrays.  The meaning of *{} is
> dependent on its position in the list.  This means that it must be able to
> count the semicolons!  If the slice is composed at runtime, it needs to
> operate at runtime as well, and this implies that the called function is
> told which dimension it is operating upon!

This is also true when using a lone * in an expression: the number of
elements that it represents depends on which dimension it appears in.
As well, a similar point applies to **.

IIRC, there's supposed to be a 'shape' method that provides
introspection on the index.  Exactly what it's capable of and how it
works has not been established AFAIK.

> Is it possible to write:
>        @i = (1, 3, *-1);
>        say @data[$i];
> and get the same meaning as
>        say @data[1, 3, *-1]?

I believe so.  IIRC, evaluation of * is lazy; it gets postponed until
there's enough context to establish what its meaning is supposed to
be.

-- 
Jonathan "Dataweaver" Lang


<Prev in Thread] Current Thread [Next in Thread>