From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 171CD17CB508 for ; Sun, 28 Oct 2012 11:17:01 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id A453AEA6B4A for ; Sun, 28 Oct 2012 11:28:28 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id B33A497A82C for ; Sun, 28 Oct 2012 11:28:28 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vu7TBKqpDIi2 for ; Sun, 28 Oct 2012 11:28:28 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 78E1697A82B for ; Sun, 28 Oct 2012 11:28:28 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 2642895244A for ; Sun, 28 Oct 2012 11:28:26 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id BAB973C21E22D; Sun, 28 Oct 2012 11:25:48 +0900 (JST) Received: from fluorine.ruby-lang.org (www.rubyist.net [210.251.121.216]) by carbon.ruby-lang.org (Postfix) with ESMTP id 31F823C21E2E6 for ; Sun, 28 Oct 2012 11:25:37 +0900 (JST) Received: from ruby-lang.org (localhost [127.0.0.1]) by fluorine.ruby-lang.org (Postfix) with ESMTP id B1A3D3EE27 for ; Sun, 28 Oct 2012 11:25:36 +0900 (JST) Delivered-To: ruby-core@ruby-lang.org Date: Sun, 28 Oct 2012 11:25:41 +0900 Posted: Sun, 28 Oct 2012 11:25:35 +0900 From: "duckinator (Nick Markwell)" Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:48511] [ruby-trunk - Feature #6727] Add Array#rest (with implementation) To: ruby-core@ruby-lang.org Message-Id: References: X-ML-Name: ruby-core X-Mail-Count: 48511 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= X-Mailer: Redmine X-Redmine-Issue-Author: duckinator X-Redmine-Issue-Assignee: matz X-Auto-Response-Suppress: OOF X-Redmine-Issue-Id: 6727 X-Redmine-Mailinglistintegration-Message-Ids: 20715 X-Redmine-Project: ruby-trunk Auto-Submitted: auto-generated X-Redmine-Site: Ruby Issue Tracking System X-Redmine-Host: bugs.ruby-lang.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: 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: (()) Patch: (()) Diff: (()) =end -- http://bugs.ruby-lang.org/