ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation)
@ 2012-07-13  4:25 duckinator (Nick Markwell)
  2012-07-13  4:55 ` [ruby-core:46378] [ruby-trunk - Feature #6727][Rejected] " marcandre (Marc-Andre Lafortune)
                   ` (19 more replies)
  0 siblings, 20 replies; 25+ messages in thread
From: duckinator (Nick Markwell) @ 2012-07-13  4:25 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been reported by duckinator (Nick Markwell).

----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727

Author: duckinator (Nick Markwell)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46378] [ruby-trunk - Feature #6727][Rejected] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
@ 2012-07-13  4:55 ` marcandre (Marc-Andre Lafortune)
  2012-07-13  5:22 ` [ruby-core:46380] [ruby-trunk - Feature #6727] " duckinator (Nick Markwell)
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: marcandre (Marc-Andre Lafortune) @ 2012-07-13  4:55 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Rejected

There are other choices besides `rest = arr[1..-1]`:

    rest = arr.drop(1)
    _, *rest = arr

See also http://bugs.ruby-lang.org/projects/ruby/wiki/HowToRequestFeatures
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-27994

Author: duckinator (Nick Markwell)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46380] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
  2012-07-13  4:55 ` [ruby-core:46378] [ruby-trunk - Feature #6727][Rejected] " marcandre (Marc-Andre Lafortune)
@ 2012-07-13  5:22 ` duckinator (Nick Markwell)
  2012-07-13  5:33 ` [ruby-core:46381] " duckinator (Nick Markwell)
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: duckinator (Nick Markwell) @ 2012-07-13  5:22 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by duckinator (Nick Markwell).


>    rest = arr.drop(1)
>    _, *rest = arr

Those two methods you mentioned "work," but the first isn't very clear on its intent, and the second cannot be used as a statement (which is where I have personally seen [1..-1] used the most). 


> See also http://bugs.ruby-lang.org/projects/ruby/wiki/HowToRequestFeatures

1. Insure it's a meaningful improvement
  * Yes, this improvement is discussed in multiple Google search results and has received positive feedback when I mentioned it elsewhere.
  * There are already ways to achieve similar results, but they don't convey their purpose well.
  * I have seen, and used arr[1..-1] countless times. Also see above statement regarding positive feedback.
2. Think about it
  * What's a good name? Array#rest
  * What exact arguments does it accept? None.
  * What does it return? A new Array.
  * Any risk of incompatibility? No.
3. Write it up
  * The title was apparently good, as it was not ignored.
  * The current situation is improved because Array#rest is clear about your intent, 
  * I made a concise but complete proposal.
  * I did not address the objection of .drop(1), because I had forgotten about it. I do hope `_, *rest = arr` was purely for demonstrative purposes.

4. Feature request already opened, with patch.



Is there any reason for this being rejected besides the existence of (({arr.drop(1)})) and your other method which (in my opinion) should not be necessary unless you're doing (({first, *rest = arr}))?

----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-27996

Author: duckinator (Nick Markwell)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46381] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
  2012-07-13  4:55 ` [ruby-core:46378] [ruby-trunk - Feature #6727][Rejected] " marcandre (Marc-Andre Lafortune)
  2012-07-13  5:22 ` [ruby-core:46380] [ruby-trunk - Feature #6727] " duckinator (Nick Markwell)
@ 2012-07-13  5:33 ` duckinator (Nick Markwell)
  2012-07-13  5:46 ` [ruby-core:46382] " programble (Curtis McEnroe)
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: duckinator (Nick Markwell) @ 2012-07-13  5:33 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by duckinator (Nick Markwell).


And I just double-checked if those behave the same, and they do *not*:

Incorrect:

>> [].drop(1)
=> []


>> first, *rest = []
=> []
>> first
=> nil
>> rest
=> nil

Correct:

>> [][1..-1]
=> nil

>> [].rest
=> nil

So it would appear there are not other choices besides rest = arr[1..-1], at least not that fit on a single line.
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-27997

Author: duckinator (Nick Markwell)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46382] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (2 preceding siblings ...)
  2012-07-13  5:33 ` [ruby-core:46381] " duckinator (Nick Markwell)
@ 2012-07-13  5:46 ` programble (Curtis McEnroe)
  2012-07-13  6:01 ` [ruby-core:46384] " tsion (Scott Olson)
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: programble (Curtis McEnroe) @ 2012-07-13  5:46 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by programble (Curtis McEnroe).


+1, This is a much cleaner way to achieve the exact same as ary[1..-1]
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-27998

Author: duckinator (Nick Markwell)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46384] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (3 preceding siblings ...)
  2012-07-13  5:46 ` [ruby-core:46382] " programble (Curtis McEnroe)
@ 2012-07-13  6:01 ` tsion (Scott Olson)
  2012-07-13 11:30 ` [ruby-core:46388] " Eregon (Benoit Daloze)
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: tsion (Scott Olson) @ 2012-07-13  6:01 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by tsion (Scott Olson).


I agree, I see and use ary[1..-1] quite a lot, and ary.rest would convey the meaning a lot better.

And it isn't just the ugliness of the syntax of ary[1..-1] that makes it undesirable, there's also the fact that it is zero-based from the front end and one-based from the back end (I know this can't really be helped because 0 == -0, but it does make Array#rest more desirable).

On top of that, I think #first and #rest make a nice pair, like head and tail from Haskell or any language with cons lists.
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-28000

Author: duckinator (Nick Markwell)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46388] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (4 preceding siblings ...)
  2012-07-13  6:01 ` [ruby-core:46384] " tsion (Scott Olson)
@ 2012-07-13 11:30 ` Eregon (Benoit Daloze)
  2012-07-13 13:44 ` [ruby-core:46391] [ruby-trunk - Feature #6727][Assigned] " naruse (Yui NARUSE)
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Eregon (Benoit Daloze) @ 2012-07-13 11:30 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by Eregon (Benoit Daloze).


tsion (Scott Olson) wrote: 
> On top of that, I think #first and #rest make a nice pair, like head and tail from Haskell or any language with cons lists.

An Array is not a cons list. #rest is O(n) here, compared to O(1) with cons.
So, doing ary[1..-1] or tail is something not very efficient, which you probably do not want most of the time (at least, not in a loop taking one element at a time with #first/#rest).
If it is for removing the first items, because for example, the Array is a set of lines and the first is a header, I'm fine with drop(1).

@duckinator: Could you show us a real use case for Array#rest ?
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-28003

Author: duckinator (Nick Markwell)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46391] [ruby-trunk - Feature #6727][Assigned] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (5 preceding siblings ...)
  2012-07-13 11:30 ` [ruby-core:46388] " Eregon (Benoit Daloze)
@ 2012-07-13 13:44 ` naruse (Yui NARUSE)
  2012-07-13 14:31 ` [ruby-core:46392] [ruby-trunk - Feature #6727] " marcandre (Marc-Andre Lafortune)
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: naruse (Yui NARUSE) @ 2012-07-13 13:44 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by naruse (Yui NARUSE).

Status changed from Rejected to Assigned
Assignee set to matz (Yukihiro Matsumoto)


----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-28007

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46392] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (6 preceding siblings ...)
  2012-07-13 13:44 ` [ruby-core:46391] [ruby-trunk - Feature #6727][Assigned] " naruse (Yui NARUSE)
@ 2012-07-13 14:31 ` marcandre (Marc-Andre Lafortune)
  2012-07-13 15:00 ` [ruby-core:46395] " trans (Thomas Sawyer)
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: marcandre (Marc-Andre Lafortune) @ 2012-07-13 14:31 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by marcandre (Marc-Andre Lafortune).


So Matz will decide one day, then.

Here are further objections in the meantime.

duckinator (Nick Markwell) wrote:
> >    rest = arr.drop(1)
> >    _, *rest = arr
> 
> Those two methods you mentioned "work," but the first isn't very clear on its intent

How is the result of dropping the first element not clear? Drop the first element and give me the rest...

> and the second cannot be used as a statement (which is where I have personally seen [1..-1] used the most).

Since you haven't yet given any real world example, that's possible, but I would guess that many times you will also use the first element of the array, no?

Then that's a good pattern to use. Or `foo = arr.shift`.

> 1. Insure it's a meaningful improvement
>   * Yes, this improvement is discussed in multiple Google search results and has received positive feedback when I mentioned it elsewhere.

It would be interesting to see examples in actual code / gems. In the whole of Rails' code, I found exactly *one* case of `array[1..-1]`

> 2. Think about it
>   * What's a good name? Array#rest

"rest" from what?

>   * What exact arguments does it accept? None.

why not? how about [2..-1]?

>   * What does it return? If the Array is empty, nil, otherwise, a new Array.
> * I did not address the objection of .drop(1), because I had forgotten about it.

Is the distinction between `[].rest == nil` and `[1].rest == []` useful? How/when? In particular, in what kind of case would the *only* difference between `arr.drop(1)` and `arr.rest` be useful?

You would like a new method which does exactly what `drop(1)` does, but with less versatility (no way to do `rest(2)`, say) and with a single difference in the case of an empty array.

>   * I do hope `_, *rest = arr` was purely for demonstrative purposes.

The '_' part was, but not the pattern. When you deal with the first part of the array, the pattern can be very useful.

----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-28008

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46395] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (7 preceding siblings ...)
  2012-07-13 14:31 ` [ruby-core:46392] [ruby-trunk - Feature #6727] " marcandre (Marc-Andre Lafortune)
@ 2012-07-13 15:00 ` trans (Thomas Sawyer)
  2012-07-13 15:34 ` [ruby-core:46396] " duckinator (Nick Markwell)
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: trans (Thomas Sawyer) @ 2012-07-13 15:00 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by trans (Thomas Sawyer).


Rather then haphazard method additions in this area I still think a better approach would be a common mixin.

http://rdoc.info/github/rubyworks/facets/master/Indexable

It's like Enumerable, but for a different set of functionality. Depending only on a minimal set of methods to facilitate the rest creates a more robust and flexible system. Call it "Occam's Principle of Interfaces" (though the principle probably already has another name?)

----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-28011

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:46396] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (8 preceding siblings ...)
  2012-07-13 15:00 ` [ruby-core:46395] " trans (Thomas Sawyer)
@ 2012-07-13 15:34 ` duckinator (Nick Markwell)
  2012-10-27 15:14 ` [ruby-core:48487] " yhara (Yutaka HARA)
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: duckinator (Nick Markwell) @ 2012-07-13 15:34 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by duckinator (Nick Markwell).


> @duckinator: Could you show us a real use case for Array#rest ?

I'll add another update in a bit with examples.


Marc-Andre:

You raised some good objections. If you don't think I answer all of them let me know, because I want this added, but I want it added properly.


> How is the result of dropping the first element not clear? Drop the first element and give me the rest...

Sorry, that was bad phrasing on my part. I meant it's not as clear as it *could be.*

> It would be interesting to see examples in actual code / gems. In the whole of Rails' code, I found exactly *one* case of `array[1..-1]`

I'll look around for some and add another update in a bit.

> "rest" from what?

The "rest" of the Array, since it goes with "first." An alternative name would be "tail," but it's usually head/tail so may lead people to expect "head" to work. It's also serving the same purpose as "cdr," but this isn't lisp, and that name's about as clear as mud to anyone who's not used a lisp dialect before. Do you have a name you feel would fit better than "rest"?

> Is the distinction between `[].rest == nil` and `[1].rest == []` useful? How/when? In particular, in what kind of case would the *only* difference between `arr.drop(1)` and `arr.rest` be useful?

To be honest, I'm not entirely sure. That was probably an issue not worth raising. Which return value is really "expected" is rather iffy because some of the languages I have seen that implement a similar function are languages that implement their equivalent of nil as an empty list. If nobody else (@programble, @tsion?) can come up with a need for `[].rest == nil`, I'd be more than willing to let it return an empty list if that turned out to be simpler.

> The '_' part was, but not the pattern. When you deal with the first part of the array, the pattern can be very useful.

Alright. I apologize if I came off as rude: my (rather foolish, admittedly) assumption was that you meant that as a way to *only* get `rest`, and that came across as a bit odd, to put it mildly.



Thomas:

> Rather then haphazard method additions in this area I still think a better approach would be a common mixin.

I did not know about Indexable, thanks for mentioning it. I agree that using a common mixin would be a far better approach. Will take a closer look at that after I have lunch.
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-28013

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:48487] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (9 preceding siblings ...)
  2012-07-13 15:34 ` [ruby-core:46396] " duckinator (Nick Markwell)
@ 2012-10-27 15:14 ` yhara (Yutaka HARA)
  2012-10-28  2:25 ` [ruby-core:48511] " duckinator (Nick Markwell)
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: yhara (Yutaka HARA) @ 2012-10-27 15:14 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by yhara (Yutaka HARA).

Category set to core
Target version set to next minor


----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-31818

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:48511] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (10 preceding siblings ...)
  2012-10-27 15:14 ` [ruby-core:48487] " yhara (Yutaka HARA)
@ 2012-10-28  2:25 ` duckinator (Nick Markwell)
  2012-10-28 11:25 ` [ruby-core:48515] " Eregon (Benoit Daloze)
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: duckinator (Nick Markwell) @ 2012-10-28  2:25 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by duckinator (Nick Markwell).


Sorry that I forgot to check this again before.


I've done a bit of thinking and poking around since I ran across this again today.


Regarding [].rest == nil vs [].rest == []:
[] is treated as a truthy value, so there if rest returns that, then there is a significant difference when #rest is used in place of [1..-1] -- you'd have to check if the original list is empty yourself, so *if this gets added* it is of no use unless it returns nil under those circumstances.

Regarding examples of it used in practice:

Just from code I happened to already have on my system, there is 501 instances of [1..-1] in Ruby code.

https://gist.github.com/3967189

Out of what I have on my system it is, surprisingly, used mostly in relation to Ruby interpreters: 217 instances in MRI's git repo, 162 instances in Rubinius' git repo, 95 instances in JRuby's git repo.

Aside from that, on my system the usages are mostly small: 4 uses by Bundler, 11 instances by what I believe are WebKit's build scripts, 4 times by cinch, and 8 times in various other things.

Other thoughts:

Perhaps Array#rest(n=1) being equivalent to Array#[n..-1], including returning nil for [].rest, would be a better approach? That way it isn't strict to the point of being nearly useless, but is still short and to the point.


----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-31845

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:48515] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (11 preceding siblings ...)
  2012-10-28  2:25 ` [ruby-core:48511] " duckinator (Nick Markwell)
@ 2012-10-28 11:25 ` Eregon (Benoit Daloze)
  2013-11-09 20:12 ` [ruby-core:58239] " baweaver (Brandon Weaver)
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Eregon (Benoit Daloze) @ 2012-10-28 11:25 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by Eregon (Benoit Daloze).


duckinator (Nick Markwell) wrote:
> Regarding examples of it used in practice:
> 
> Just from code I happened to already have on my system, there is 501 instances of [1..-1] in Ruby code.
> 
> https://gist.github.com/3967189

Thank you for searching for examples!

I guess you are aware many of these examples are using String#[1..-1].
A few examples are using MatchData#[1..-1], which should be replaced by MathData#captures.

For Bundler, only 1 example is Array#[], the 3 others are String#[].
For Cinch, 2 of 4 are Array#[] (1 MatchData#[] and 1 String#[]).
Oddly enough, 2 out of these 3 examples of Array#[] are actually removing the first line of an Exception backtrace.

For my part, I don't feel a real need for Array#rest, and I dislike #rest because it would imply the structure has an head and a tail, which Array does not. I think having a long/not-so-good-looking way to take all elements but the first is an advantage as it does not encourage this operation which is rarely optimal. As I said earlier, I think Array#drop is nicely used in this case.
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-31863

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58239] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (12 preceding siblings ...)
  2012-10-28 11:25 ` [ruby-core:48515] " Eregon (Benoit Daloze)
@ 2013-11-09 20:12 ` baweaver (Brandon Weaver)
  2013-11-09 20:38   ` [ruby-core:58240] " Fuad Saud
  2013-11-10 15:27 ` [ruby-core:58249] " marcandre (Marc-Andre Lafortune)
                   ` (5 subsequent siblings)
  19 siblings, 1 reply; 25+ messages in thread
From: baweaver (Brandon Weaver) @ 2013-11-09 20:12 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by baweaver (Brandon Weaver).


As this seems to have been either dead-ended or otherwise, I'd like to bring it back up.

Most of the arguments I head as to why not to include a rest or tail method is that Ruby is not Lisp, or that there's a hack-around method that works the same way. The two objections I have to such reasoning are that Matz himself designed Ruby in part after Lisp, and that the point of Ruby is to be succinct and clear.

I strongly believe that array.rest or array.tail are clearer than array[1..-10] or rest = array.drop. The point is to be clear and concise, and this clearly aims to improve upon such.

As per the usefulness of such a construct, tail-recursion and functional constructs come heavily to mind. 

Within the last year I would have made an argument that lambda was not needed in the language because I had not tried to use it, and I have been heavily proven wrong in that thinking. A C programmer may think closures are useless because they have never used one in production. You use the tools you are given, and in some cases become biased towards them.

That being said, we could also add car and cdr just for warm fuzzy feelings while we're at it ;)
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-42829

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58240] Re: [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2013-11-09 20:12 ` [ruby-core:58239] " baweaver (Brandon Weaver)
@ 2013-11-09 20:38   ` Fuad Saud
  0 siblings, 0 replies; 25+ messages in thread
From: Fuad Saud @ 2013-11-09 20:38 UTC (permalink / raw)
  To: Ruby developers

[-- Attachment #1: Type: text/plain, Size: 2304 bytes --]

I proposed it as well in #9023 in the CommonRuby list. I don't think the
arguments given there are enough to justify not implementing such an useful
method.
On Nov 9, 2013 6:13 PM, "baweaver (Brandon Weaver)" <
brandon_weaver@baweaver.com> wrote:

>
> Issue #6727 has been updated by baweaver (Brandon Weaver).
>
>
> As this seems to have been either dead-ended or otherwise, I'd like to
> bring it back up.
>
> Most of the arguments I head as to why not to include a rest or tail
> method is that Ruby is not Lisp, or that there's a hack-around method that
> works the same way. The two objections I have to such reasoning are that
> Matz himself designed Ruby in part after Lisp, and that the point of Ruby
> is to be succinct and clear.
>
> I strongly believe that array.rest or array.tail are clearer than
> array[1..-10] or rest = array.drop. The point is to be clear and concise,
> and this clearly aims to improve upon such.
>
> As per the usefulness of such a construct, tail-recursion and functional
> constructs come heavily to mind.
>
> Within the last year I would have made an argument that lambda was not
> needed in the language because I had not tried to use it, and I have been
> heavily proven wrong in that thinking. A C programmer may think closures
> are useless because they have never used one in production. You use the
> tools you are given, and in some cases become biased towards them.
>
> That being said, we could also add car and cdr just for warm fuzzy
> feelings while we're at it ;)
> ----------------------------------------
> Feature #6727: Add Array#rest (with implementation)
> https://bugs.ruby-lang.org/issues/6727#change-42829
>
> Author: duckinator (Nick Markwell)
> Status: Assigned
> Priority: Normal
> Assignee: matz (Yukihiro Matsumoto)
> Category: core
> Target version: next minor
>
>
> =begin
> I run into many instances where I end up using (({arr[1..-1]})), so I
> decided to add (({arr.rest})) to make that a bit less hideous.
>
> Branch on github: ((<URL:
> https://github.com/duckinator/ruby/compare/feature/array_rest>))
>
> Patch: ((<URL:
> https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))
>
> Diff: ((<URL:
> https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
> =end
>
>
> --
> http://bugs.ruby-lang.org/
>

[-- Attachment #2: Type: text/html, Size: 3108 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58249] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (13 preceding siblings ...)
  2013-11-09 20:12 ` [ruby-core:58239] " baweaver (Brandon Weaver)
@ 2013-11-10 15:27 ` marcandre (Marc-Andre Lafortune)
  2013-11-11  7:19   ` [ruby-core:58267] " "Martin J. Dürst"
  2013-11-10 16:47 ` [ruby-core:58256] " Hanmac (Hans Mackowiak)
                   ` (4 subsequent siblings)
  19 siblings, 1 reply; 25+ messages in thread
From: marcandre (Marc-Andre Lafortune) @ 2013-11-10 15:27 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by marcandre (Marc-Andre Lafortune).


Hi,

duckinator (Nick Markwell) wrote:
> Regarding examples of it used in practice:
> 
> Just from code I happened to already have on my system, there is 501 instances of [1..-1] in Ruby code.
> 
> https://gist.github.com/3967189
>
> Out of what I have on my system it is, surprisingly, used mostly in relation to Ruby interpreters: 217 instances in MRI's git repo, 162 instances in Rubinius' git repo, 95 instances in JRuby's git repo.
> 
> Aside from that, on my system the usages are mostly small: 4 uses by Bundler, 11 instances by what I believe are WebKit's build scripts, 4 times by cinch, and 8 times in various other things.

I believe that the vast majority of these examples are for strings, not arrays.

----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-42840

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58256] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (14 preceding siblings ...)
  2013-11-10 15:27 ` [ruby-core:58249] " marcandre (Marc-Andre Lafortune)
@ 2013-11-10 16:47 ` Hanmac (Hans Mackowiak)
  2013-11-11  7:21   ` [ruby-core:58268] " "Martin J. Dürst"
  2013-11-11  9:18 ` [ruby-core:58273] " alexeymuranov (Alexey Muranov)
                   ` (3 subsequent siblings)
  19 siblings, 1 reply; 25+ messages in thread
From: Hanmac (Hans Mackowiak) @ 2013-11-10 16:47 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by Hanmac (Hans Mackowiak).


i think in most cases we want something like ary[1..-1].each  but wouldnt it be better if we have an each method like 

each_only(1..-1) {}

that does that for us without making an new array?
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-42847

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58267] Re: [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2013-11-10 15:27 ` [ruby-core:58249] " marcandre (Marc-Andre Lafortune)
@ 2013-11-11  7:19   ` "Martin J. Dürst"
  0 siblings, 0 replies; 25+ messages in thread
From: "Martin J. Dürst" @ 2013-11-11  7:19 UTC (permalink / raw)
  To: Ruby developers; +Cc: marcandre (Marc-Andre Lafortune)

On 2013/11/11 0:27, marcandre (Marc-Andre Lafortune) wrote:

> duckinator (Nick Markwell) wrote:

> I believe that the vast majority of these examples are for strings, not arrays.

That might suggest adding #rest to String, too.

Regards,   Martin.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58268] Re: [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2013-11-10 16:47 ` [ruby-core:58256] " Hanmac (Hans Mackowiak)
@ 2013-11-11  7:21   ` "Martin J. Dürst"
  0 siblings, 0 replies; 25+ messages in thread
From: "Martin J. Dürst" @ 2013-11-11  7:21 UTC (permalink / raw)
  To: Ruby developers; +Cc: Hanmac (Hans Mackowiak)

On 2013/11/11 1:47, Hanmac (Hans Mackowiak) wrote:

> i think in most cases we want something like ary[1..-1].each  but wouldnt it be better if we have an each method like
>
> each_only(1..-1) {}

#each currently doesn't have arguments. So this could even be

each(1..-1) {}

Regards,   Martin.

> that does that for us without making an new array?

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58273] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (15 preceding siblings ...)
  2013-11-10 16:47 ` [ruby-core:58256] " Hanmac (Hans Mackowiak)
@ 2013-11-11  9:18 ` alexeymuranov (Alexey Muranov)
  2013-11-11  9:27 ` [ruby-core:58274] " Hanmac (Hans Mackowiak)
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2013-11-11  9:18 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by alexeymuranov (Alexey Muranov).


duerst (Martin Dürst) wrote:
> On 2013/11/11 1:47, Hanmac (Hans Mackowiak) wrote:
>  
>  > i think in most cases we want something like ary[1..-1].each  but wouldnt it be better if we have an each method like
>  >
>  > each_only(1..-1) {}
>  
>  #each currently doesn't have arguments. So this could even be
>  
>  each(1..-1) {}

If #each is to take arguments,  would suggest

  [1, 2, 'a', :b, 3].each(Integer).map{|x| 2*x } # => [2, 4, 6]

----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-42860

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58274] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (16 preceding siblings ...)
  2013-11-11  9:18 ` [ruby-core:58273] " alexeymuranov (Alexey Muranov)
@ 2013-11-11  9:27 ` Hanmac (Hans Mackowiak)
  2013-11-11 17:29 ` [ruby-core:58283] " fuadksd (Fuad Saud)
  2019-08-14  8:51 ` [ruby-core:94346] [Ruby master Feature#6727] " mame
  19 siblings, 0 replies; 25+ messages in thread
From: Hanmac (Hans Mackowiak) @ 2013-11-11  9:27 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by Hanmac (Hans Mackowiak).


alexeymuranov (Alexey Muranov) wrote:
> If #each is to take arguments,  would suggest
> 
>   [1, 2, 'a', :b, 3].each(Integer).map{|x| 2*x } # => [2, 4, 6]

ok that would be like #grep, but i want something that uses index, not the object itself
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-42861

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58283] [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (17 preceding siblings ...)
  2013-11-11  9:27 ` [ruby-core:58274] " Hanmac (Hans Mackowiak)
@ 2013-11-11 17:29 ` fuadksd (Fuad Saud)
  2013-11-12  1:04   ` [ruby-core:58285] " "Martin J. Dürst"
  2019-08-14  8:51 ` [ruby-core:94346] [Ruby master Feature#6727] " mame
  19 siblings, 1 reply; 25+ messages in thread
From: fuadksd (Fuad Saud) @ 2013-11-11 17:29 UTC (permalink / raw)
  To: ruby-core


Issue #6727 has been updated by fuadksd (Fuad Saud).


Reading back the comments, I realize Indexable may be a good idea for String/Array polymorphism.
----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-42873

Author: duckinator (Nick Markwell)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:58285] Re: [ruby-trunk - Feature #6727] Add Array#rest (with implementation)
  2013-11-11 17:29 ` [ruby-core:58283] " fuadksd (Fuad Saud)
@ 2013-11-12  1:04   ` "Martin J. Dürst"
  0 siblings, 0 replies; 25+ messages in thread
From: "Martin J. Dürst" @ 2013-11-12  1:04 UTC (permalink / raw)
  To: Ruby developers

On 2013/11/12 2:29, fuadksd (Fuad Saud) wrote:
>
> Issue #6727 has been updated by fuadksd (Fuad Saud).
>
>
> Reading back the comments, I realize Indexable may be a good idea for String/Array polymorphism.

The idea is already there. If you check, you'll notice that whenever 
something makes sense both for an Array and a String (e.g. #length), 
it's the same method with the same arguments. There is no explicit 
Indexable module or superclass because for efficiency, implementations 
are separate (and sharing implementations would be the main/only reason 
for using a module or a superclass in Ruby).

But there is also some aspect in which the two classes don't match. For 
Array, #each iterates over elements. But for String, #each doesn't 
exist. For the discussion in this issue, String#each would have to 
iterate over characters, but in Ruby 1.8, it iterated over lines, and 
that's why it was removed altogether from Ruby 1.9, and we have 
#each_char, #each_byte, #each_line now.

Regards,   Martin.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [ruby-core:94346] [Ruby master Feature#6727] Add Array#rest (with implementation)
  2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
                   ` (18 preceding siblings ...)
  2013-11-11 17:29 ` [ruby-core:58283] " fuadksd (Fuad Saud)
@ 2019-08-14  8:51 ` mame
  19 siblings, 0 replies; 25+ messages in thread
From: mame @ 2019-08-14  8:51 UTC (permalink / raw)
  To: ruby-core

Issue #6727 has been updated by mame (Yusuke Endoh).

Status changed from Assigned to Feedback

Now we have an endless range which allows us to write `arr[1..]`.  It is much less hideous than `arr[1..-1]`, IMO.  Do you still want `Array#rest`?

----------------------------------------
Feature #6727: Add Array#rest (with implementation)
https://bugs.ruby-lang.org/issues/6727#change-80749

* Author: duckinator (Marie Markwell)
* Status: Feedback
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin
I run into many instances where I end up using (({arr[1..-1]})), so I decided to add (({arr.rest})) to make that a bit less hideous.

Branch on github: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest>))

Patch: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.patch>))

Diff: ((<URL:https://github.com/duckinator/ruby/compare/feature/array_rest.diff>))
=end



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2019-08-14  8:51 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-13  4:25 [ruby-core:46377] [ruby-trunk - Feature #6727][Open] Add Array#rest (with implementation) duckinator (Nick Markwell)
2012-07-13  4:55 ` [ruby-core:46378] [ruby-trunk - Feature #6727][Rejected] " marcandre (Marc-Andre Lafortune)
2012-07-13  5:22 ` [ruby-core:46380] [ruby-trunk - Feature #6727] " duckinator (Nick Markwell)
2012-07-13  5:33 ` [ruby-core:46381] " duckinator (Nick Markwell)
2012-07-13  5:46 ` [ruby-core:46382] " programble (Curtis McEnroe)
2012-07-13  6:01 ` [ruby-core:46384] " tsion (Scott Olson)
2012-07-13 11:30 ` [ruby-core:46388] " Eregon (Benoit Daloze)
2012-07-13 13:44 ` [ruby-core:46391] [ruby-trunk - Feature #6727][Assigned] " naruse (Yui NARUSE)
2012-07-13 14:31 ` [ruby-core:46392] [ruby-trunk - Feature #6727] " marcandre (Marc-Andre Lafortune)
2012-07-13 15:00 ` [ruby-core:46395] " trans (Thomas Sawyer)
2012-07-13 15:34 ` [ruby-core:46396] " duckinator (Nick Markwell)
2012-10-27 15:14 ` [ruby-core:48487] " yhara (Yutaka HARA)
2012-10-28  2:25 ` [ruby-core:48511] " duckinator (Nick Markwell)
2012-10-28 11:25 ` [ruby-core:48515] " Eregon (Benoit Daloze)
2013-11-09 20:12 ` [ruby-core:58239] " baweaver (Brandon Weaver)
2013-11-09 20:38   ` [ruby-core:58240] " Fuad Saud
2013-11-10 15:27 ` [ruby-core:58249] " marcandre (Marc-Andre Lafortune)
2013-11-11  7:19   ` [ruby-core:58267] " "Martin J. Dürst"
2013-11-10 16:47 ` [ruby-core:58256] " Hanmac (Hans Mackowiak)
2013-11-11  7:21   ` [ruby-core:58268] " "Martin J. Dürst"
2013-11-11  9:18 ` [ruby-core:58273] " alexeymuranov (Alexey Muranov)
2013-11-11  9:27 ` [ruby-core:58274] " Hanmac (Hans Mackowiak)
2013-11-11 17:29 ` [ruby-core:58283] " fuadksd (Fuad Saud)
2013-11-12  1:04   ` [ruby-core:58285] " "Martin J. Dürst"
2019-08-14  8:51 ` [ruby-core:94346] [Ruby master Feature#6727] " mame

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).