[perl #132543] Can't tail a tail.

2017-12-07 Thread Zoffix Znet via RT
On Thu, 07 Dec 2017 15:48:35 -0800, comdog wrote:
> I first asked about this on Stackoverflow:
> 
> https://stackoverflow.com/q/47704428/2766176
> 
> A .tail on a .tail appears to do the wrong thing:
> 
> > my $list = ;
> (a b c d e f g h i j)
> 
> > $list.tail(5).tail
> Nil
> 
> But throwing a list in there works:
> 
> > $list.tail(5).list.tail
> j
> 
> Timo said:
> 
> .tail and .tail(1) are implemented with
> Rakudo::Iterator.LastValue and
> Rakudo::Iterator.LastNValues respectively, which differ
> quite a bit in implementation.
> https://github.com/rakudo/rakudo/blob/master/src/core/Rakudo/Iterator.pm#L1807
> 
> And he figures:
> 
> tail on the List takes an iterator and skips it ahead $n
> items. then, the tail method on Seq calls count-only on
> it to figure out how far to skip ahead to get the last
> $m items. However, count-only on the first iterator just
> gives you the total number of items in the original
> list. It should probably either signal an error when
> asked for count-only, or it should calculate the proper
> amount of items left.


Thank you for the report. This is now fixed.

Fix:   https://github.com/rakudo/rakudo/commit/af9812fa73
Tests: https://github.com/perl6/roast/commit/88a12f6984f0b57e9
   https://github.com/perl6/roast/commit/1743894c03


[perl #132543] Can't tail a tail.

2017-12-07 Thread Zoffix Znet via RT
On Thu, 07 Dec 2017 15:48:35 -0800, comdog wrote:
> I first asked about this on Stackoverflow:
> 
> https://stackoverflow.com/q/47704428/2766176
> 
> A .tail on a .tail appears to do the wrong thing:
> 
> > my $list = ;
> (a b c d e f g h i j)
> 
> > $list.tail(5).tail
> Nil
> 
> But throwing a list in there works:
> 
> > $list.tail(5).list.tail
> j
> 
> Timo said:
> 
> .tail and .tail(1) are implemented with
> Rakudo::Iterator.LastValue and
> Rakudo::Iterator.LastNValues respectively, which differ
> quite a bit in implementation.
> https://github.com/rakudo/rakudo/blob/master/src/core/Rakudo/Iterator.pm#L1807
> 
> And he figures:
> 
> tail on the List takes an iterator and skips it ahead $n
> items. then, the tail method on Seq calls count-only on
> it to figure out how far to skip ahead to get the last
> $m items. However, count-only on the first iterator just
> gives you the total number of items in the original
> list. It should probably either signal an error when
> asked for count-only, or it should calculate the proper
> amount of items left.


Thank you for the report. This is now fixed.

Fix:   https://github.com/rakudo/rakudo/commit/af9812fa73
Tests: https://github.com/perl6/roast/commit/88a12f6984f0b57e9
   https://github.com/perl6/roast/commit/1743894c03


[perl #132543] Can't tail a tail.

2017-12-07 Thread brian d foy
# New Ticket Created by  "brian d foy" 
# Please include the string:  [perl #132543]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=132543 >


I first asked about this on Stackoverflow:

https://stackoverflow.com/q/47704428/2766176

A .tail on a .tail appears to do the wrong thing:

> my $list = ;
(a b c d e f g h i j)

> $list.tail(5).tail
Nil

But throwing a list in there works:

> $list.tail(5).list.tail
j

Timo said:

.tail and .tail(1) are implemented with
Rakudo::Iterator.LastValue and
Rakudo::Iterator.LastNValues respectively, which differ
quite a bit in implementation.

https://github.com/rakudo/rakudo/blob/master/src/core/Rakudo/Iterator.pm#L1807

And he figures:

tail on the List takes an iterator and skips it ahead $n
items. then, the tail method on Seq calls count-only on
it to figure out how far to skip ahead to get the last
$m items. However, count-only on the first iterator just
gives you the total number of items in the original
list. It should probably either signal an error when
asked for count-only, or it should calculate the proper
amount of items left.


Re: [perl #124832]

2017-12-07 Thread 陈梓立 via RT
rakudo#1296 could replace this one.

2017-12-03 14:10 GMT+08:00 陈梓立 :

> Now the issue is quite different.
>
> I think it becomes an issue about `but`, not about `Cannot convert string
> to number`
>


[perl #124832]

2017-12-07 Thread 陈梓立 via RT
Now the issue is quite different.

I think it becomes an issue about `but`, not about `Cannot convert string
to number`


[perl #124952]

2017-12-07 Thread 陈梓立 via RT
Note that if you call `next`, then the order is correct.


[perl #124979]

2017-12-07 Thread 陈梓立 via RT
This is not limited in operator overloading

```
my $a;
$a := { $^a + $^b }
# ok
```

```
my 
 := { $^a + $^b }
# Cannot use bind operator with this left-hand side
```

```
my  := { $^a + $^b }
say a(1, 2)
# 3
```

```
my : := { $^a + $^b };

say 1 plus 2 plus 3

# 6
```


Note that it is all well if use `=` instead of `:=`

```
{
  my :;
  BEGIN {
: = { $^a + $^b };
  }

  is 3 plus 5, 8, 'overloading an operator using "my :<...>" worked';
}
# ok 1 - overloading an operator using "my :<...>" worked
```

This test is moved to S06-operator-overloading/infix.t, BTW


[perl #124983]

2017-12-07 Thread 陈梓立 via RT
1. now it's moved to S06-operator-overloading/infix.t

2. note that default Left-associative works, this ticket in fact about
reserved words. See the example below:

```
{
  my sub infix: ($a, $b) {
  $a ** $b;
  }
  is (2 Z 1 Z 2), 4, "default Left-associative works.";
}
# Calling infix:(Int, Int, Int) will never work with declared signature
($a, $b)
```

```
{
  my sub infix: ($a, $b) {
  $a ** $b;
  }
  is (2 B 1 B 2), 4, "default Left-associative works.";
}
# ok
```

```
{
  my sub infix:<.> ($a, $b) {
  $a ** $b;
  }
  is (2 . 1 . 2), 4, "default Left-associative works.";
}
# Unsupported use of . to concatenate strings; in Perl 6 please use ~
```

```
{
  my sub infix:<~> ($a, $b) {
  $a ** $b;
  }
  is (2 ~ 1 ~ 2), 4, "default Left-associative works.";
}
# ok
```

```
{
  my sub infix:<@> ($a, $b) {
  $a ** $b;
  }
  is (2 @ 1 @2), 4, "default Left-associative works.";
}
# ok
```


[perl #124983]

2017-12-07 Thread 陈梓立
1. now it's moved to S06-operator-overloading/infix.t

2. note that default Left-associative works, this ticket in fact about
reserved words. See the example below:

```
{
  my sub infix: ($a, $b) {
  $a ** $b;
  }
  is (2 Z 1 Z 2), 4, "default Left-associative works.";
}
# Calling infix:(Int, Int, Int) will never work with declared signature
($a, $b)
```

```
{
  my sub infix: ($a, $b) {
  $a ** $b;
  }
  is (2 B 1 B 2), 4, "default Left-associative works.";
}
# ok
```

```
{
  my sub infix:<.> ($a, $b) {
  $a ** $b;
  }
  is (2 . 1 . 2), 4, "default Left-associative works.";
}
# Unsupported use of . to concatenate strings; in Perl 6 please use ~
```

```
{
  my sub infix:<~> ($a, $b) {
  $a ** $b;
  }
  is (2 ~ 1 ~ 2), 4, "default Left-associative works.";
}
# ok
```

```
{
  my sub infix:<@> ($a, $b) {
  $a ** $b;
  }
  is (2 @ 1 @2), 4, "default Left-associative works.";
}
# ok
```


[perl #124832]

2017-12-07 Thread 陈梓立
Now the issue is quite different.

I think it becomes an issue about `but`, not about `Cannot convert string
to number`


[perl #124979]

2017-12-07 Thread 陈梓立
This is not limited in operator overloading

```
my $a;
$a := { $^a + $^b }
# ok
```

```
my 
 := { $^a + $^b }
# Cannot use bind operator with this left-hand side
```

```
my  := { $^a + $^b }
say a(1, 2)
# 3
```

```
my : := { $^a + $^b };

say 1 plus 2 plus 3

# 6
```


Note that it is all well if use `=` instead of `:=`

```
{
  my :;
  BEGIN {
: = { $^a + $^b };
  }

  is 3 plus 5, 8, 'overloading an operator using "my :<...>" worked';
}
# ok 1 - overloading an operator using "my :<...>" worked
```

This test is moved to S06-operator-overloading/infix.t, BTW


[perl #124952]

2017-12-07 Thread 陈梓立
Note that if you call `next`, then the order is correct.


Re: [perl #124832]

2017-12-07 Thread 陈梓立
rakudo#1296 could replace this one.

2017-12-03 14:10 GMT+08:00 陈梓立 :

> Now the issue is quite different.
>
> I think it becomes an issue about `but`, not about `Cannot convert string
> to number`
>


[perl #125488]

2017-12-07 Thread 陈梓立 via RT
So far we've fix the bugs on NEXT and LAST, while POST remained.

I added a test for this ticket perl6/roast#362