Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[svn:perl6-synopsis] r13550 - doc/trunk/design/syn

3 views
Skip to first unread message

la...@cvs.perl.org

unread,
Jan 30, 2007, 3:20:50 PM1/30/07
to perl6-l...@perl.org
Author: larry
Date: Tue Jan 30 12:20:47 2007
New Revision: 13550

Modified:
doc/trunk/design/syn/S09.pod

Log:
Another idea for *+ vs *- in subscripts


Modified: doc/trunk/design/syn/S09.pod
==============================================================================
--- doc/trunk/design/syn/S09.pod (original)
+++ doc/trunk/design/syn/S09.pod Tue Jan 30 12:20:47 2007
@@ -802,6 +802,12 @@

works...

+Alternately, C<*+0> is the first element, and the subscript dwims
+from the front or back depending on the sign. That would be more
+symmetrical, but makes the idea of C<*> in a subscript a little more
+distant from the notion of "all the keys", which would be a loss,
+and potentially makes C<+*> not mean the number of keys.
+
Conjecture: we might provide a way to declare a modular subscript that
emulates the dwimmery, perhaps by using a subset type:

TSa

unread,
Jan 30, 2007, 3:29:03 PM1/30/07
to la...@cvs.develooper.com, perl6-l...@perl.org
HaloO,

la...@cvs.develooper.com wrote:
> +Alternately, C<*+0> is the first element, and the subscript dwims
> +from the front or back depending on the sign. That would be more
> +symmetrical, but makes the idea of C<*> in a subscript a little more
> +distant from the notion of "all the keys", which would be a loss,
> +and potentially makes C<+*> not mean the number of keys.

The distinction of the three cases would be through dispatch
to different functions. The plain * goes to
&postcircumfix<[ ]>:(Array,Whatever) while the other two go
to &infix:<+>(Whatever,Int) and &infix:<->:(Whatever,Int)
respectively. In the latter cases the Whatever type somehow must
package the array. Perhaps it is actually Whatever of Array or
somesuch. The return value is a normal Int suitable for indexing
the array. Perhaps we need to restrict the second parameter to
UInt unless these two operators wrap around depending on sign ;)
That is @array[*+(-1)] actually retrieves that last entry and
@array[*-(-1)] the first =:()

Can the index be set up before using it in an array index?

my @a = 1,2,3;
my $x = *-1;
say @a[$x]; # prints 3

Would &infix:<-> return a lazy Whatever value that becomes
a specific index when it hits &postcircumfix<[ ]>? That is
we have something like Whatever arithmetic?


Regards, TSa.
--

Larry Wall

unread,
Jan 30, 2007, 3:46:37 PM1/30/07
to perl6-l...@perl.org
On Tue, Jan 30, 2007 at 09:29:03PM +0100, TSa wrote:
: HaloO,

:
: la...@cvs.develooper.com wrote:
: >+Alternately, C<*+0> is the first element, and the subscript dwims
: >+from the front or back depending on the sign. That would be more
: >+symmetrical, but makes the idea of C<*> in a subscript a little more
: >+distant from the notion of "all the keys", which would be a loss,
: >+and potentially makes C<+*> not mean the number of keys.
:
: The distinction of the three cases would be through dispatch
: to different functions. The plain * goes to
: &postcircumfix<[ ]>:(Array,Whatever) while the other two go
: to &infix:<+>(Whatever,Int) and &infix:<->:(Whatever,Int)
: respectively. In the latter cases the Whatever type somehow must
: package the array.

I don't think we want Whatever to package the array, since...

: Perhaps it is actually Whatever of Array or


: somesuch. The return value is a normal Int suitable for indexing
: the array. Perhaps we need to restrict the second parameter to
: UInt unless these two operators wrap around depending on sign ;)
: That is @array[*+(-1)] actually retrieves that last entry and
: @array[*-(-1)] the first =:()
:
: Can the index be set up before using it in an array index?
:
: my @a = 1,2,3;
: my $x = *-1;
: say @a[$x]; # prints 3
:
: Would &infix:<-> return a lazy Whatever value that becomes
: a specific index when it hits &postcircumfix<[ ]>? That is
: we have something like Whatever arithmetic?

...I think that should work. The *-1 value just means "one before
Whatever", and the dwim is, as you say, lazy. Or perhaps this generalizes
to an odd form of currying:

&replicate := * xx 42;

But then it's not clear how the eventual victim would know how to
distinguish *+42 from *-42 if it's only getting some kind of closure
to call. So I think we still have to dispatch to Whatever and let
the Whatever code extract any relevant relative information knowing
that a "dwim" was explicitly called for by use of *.

Larry

TSa

unread,
Jan 31, 2007, 6:37:36 AM1/31/07
to perl6-l...@perl.org
HaloO,

Larry Wall wrote:
> ...I think that should work. The *-1 value just means "one before
> Whatever", and the dwim is, as you say, lazy. Or perhaps this generalizes
> to an odd form of currying:
>
> &replicate := * xx 42;

Ohh, let me get that in my own words: the rhs replicates a Whatever
into a list of 42 Whatever values, then a code variable is bound to
this list. How would one access that thing? Does replicate()[*-1]
return the last Whatever and replicate()[0] the first? How does one
make use of such a Whatever value?


> But then it's not clear how the eventual victim would know how to
> distinguish *+42 from *-42 if it's only getting some kind of closure
> to call.

I don't get that. Do you mean replicate()[*+42] that would be one
after the last Whatever and replicate()[*-42] that would be the first
Whatever in the list but indexed from the back? Or do you want to
index into the Whatevers like it would be the case for a range 0..*
which dispatches to &infix:<..>:(Int,Whatever) and returns a range
that is lazy at the end. IOW, I don't understand what
&infix:<xx>:(Whatever,Int) returns. I mean what type of Whatever
value is it? I understand that it is 42 times the same thing in
a list but what it is is unspecified for the moment. Such a Whatever
value is sort of parametric and adapts to the environment it is
finally used in. The two uses I see right now is in ranges and as
array index.

BTW, are Whatever ranges applicable to arrays?

my @a = 0,1,2,3,4,5,6,7,8,9;
my $i = 5..*;
say @a[$i]; # prints 5 6 7 8 9

Is the Whateverness of the range kept and finally resolved
when applied to the array? Or does &postcircumfix:<[ ]> see
only a lazy range?


> So I think we still have to dispatch to Whatever and let
> the Whatever code extract any relevant relative information knowing
> that a "dwim" was explicitly called for by use of *.

Could you make an example of what you mean here, please. Do you mean
a dispatch to &postcircumfix:<[ ]>?


Regards, TSa.
--

TSa

unread,
Jan 31, 2007, 8:47:02 AM1/31/07
to perl6-l...@perl.org
HaloO

I wrote:
> my @a = 0,1,2,3,4,5,6,7,8,9;
> my $i = 5..*;
> say @a[$i]; # prints 5 6 7 8 9

And how about

my $i = 5..*-1;
say @a[$i]; # prints 5 6 7 8?

The rational would be that the -1 goes
into the range Whatever value, that is
when it comes to expanding it inside the
array index the following information is
available:

1) the start of the range = 5
2) the -1 of the Whatever
3) the array's last index = 9

these result in the following array access

say @a[5..9-1];

Instead of the array's last index the array length = 10
might be used and we end up with an access of @a[5..10-1].
But then how would $i = 5..* work? It would need to be
written $i = 5..^* to exclude the index 10.


Regards, TSa.
--

0 new messages