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 9E30B17D7046 for ; Sat, 20 Jun 2015 08:49:32 +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 51F6EB5D884 for ; Sat, 20 Jun 2015 09:12:37 +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 4896B97A82B for ; Sat, 20 Jun 2015 09:12:38 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me 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 ov_wdtP_QX_y for ; Sat, 20 Jun 2015 09:12:38 +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 1CF7E97A826 for ; Sat, 20 Jun 2015 09:12:38 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 1160C952441 for ; Sat, 20 Jun 2015 09:12:34 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C02DF120493; Sat, 20 Jun 2015 09:12:32 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id C743912046C for ; Sat, 20 Jun 2015 09:12:28 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=8Rj4vof4DdS5ENdaqkTd/XG5ieA=; b=ds2ALWg/kmEG9dFX1g hnS33uRWbDOEIfSDaqCIzkxiiWYFu9P9n8Q6sB6l5y1uEioCNFCPfOtf8OK5IlYl 8cdhjNzlsFMiAFkeOfmAjmtvTzM9f6JdUuyWdfz4NO3/Ji77srBTukyPhC3C4gbP 1bzDw3H77v7X5hljO0QA5CL4s= Received: by filter0811p1mdw1.sendgrid.net with SMTP id filter0811p1mdw1.9937.5584AFE82 2015-06-20 00:12:24.538719324 +0000 UTC Received: from herokuapp.com (ec2-54-242-225-72.compute-1.amazonaws.com [54.242.225.72]) by ismtpd-036 (SG) with ESMTP id 14e0e4f2431.2853.3fa5d1 for ; Sat, 20 Jun 2015 00:12:24 +0000 (UTC) Date: Sat, 20 Jun 2015 00:12:24 +0000 From: nobu@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 44247 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11286 X-Redmine-Issue-Author: 0x0dea X-Redmine-Issue-Assignee: matz X-Redmine-Sender: nobu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4XbVZ/NOWnuigjyhi3SAXpqNCqYitSmHBGiK MI4WbOaC5fUtJ5+zymBmXPLS4a0KJQa0T26DsTRQyurlUFg6Ni/A//vqFlDjKj1NMswaL7NbOS/K/k Yd7LQ9hEw1urHR2jBvQpqLpA1eqGNxn+sWEX X-ML-Name: ruby-core X-Mail-Count: 69688 Subject: [ruby-core:69688] [Ruby trunk - Feature #11286] [PATCH] Add case equality arity to Enumerable's sequence predicates. X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11286 has been updated by Nobuyoshi Nakada. D.E. Akers wrote: > I assumed `*argv` would resolve to `Qnil` in the case of no arguments, but this is indeed not the case. Nobody guarantees it. And argument check should be before making a memo object, I think. ~~~diff diff --git a/enum.c b/enum.c index c5b9d77..d6f11e5 100644 --- a/enum.c +++ b/enum.c @@ -1045,6 +1045,8 @@ enum_sort_by(VALUE obj) #define ENUMFUNC(name, argc) argc ? name##_eqq : rb_block_given_p() ? name##_iter_i : name##_i +#define MEMO_ENUM_NEW(v1) (rb_check_arity(argc, 0, 1), MEMO_NEW((v1), (argc ? *argv : 0), 0)) + #define DEFINE_ENUMFUNCS(name) \ static VALUE enum_##name##_func(VALUE result, struct MEMO *memo); \ \ @@ -1104,8 +1106,7 @@ DEFINE_ENUMFUNCS(all) static VALUE enum_all(int argc, VALUE *argv, VALUE obj) { - struct MEMO *memo = MEMO_NEW(Qtrue, argc ? *argv : 0, 0); - rb_check_arity(argc, 0, 1); + struct MEMO *memo = MEMO_ENUM_NEW(Qtrue); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(all, argc), (VALUE)memo); return memo->v1; } @@ -1145,8 +1146,7 @@ DEFINE_ENUMFUNCS(any) static VALUE enum_any(int argc, VALUE *argv, VALUE obj) { - struct MEMO *memo = MEMO_NEW(Qfalse, argc ? *argv : 0, 0); - rb_check_arity(argc, 0, 1); + struct MEMO *memo = MEMO_ENUM_NEW(Qfalse); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any, argc), (VALUE)memo); return memo->v1; } @@ -1438,8 +1438,7 @@ DEFINE_ENUMFUNCS(none) static VALUE enum_none(int argc, VALUE *argv, VALUE obj) { - struct MEMO *memo = MEMO_NEW(Qtrue, argc ? *argv : 0, 0); - rb_check_arity(argc, 0, 1); + struct MEMO *memo = MEMO_ENUM_NEW(Qtrue); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(none, argc), (VALUE)memo); return memo->v1; } ~~~ ---------------------------------------- Feature #11286: [PATCH] Add case equality arity to Enumerable's sequence predicates. https://bugs.ruby-lang.org/issues/11286#change-53063 * Author: D.E. Akers * Status: Open * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- ## Proposal It is proposed that `Enumerable`'s sequence predicates (`#all?`, `#any?`, `#none?`, and `#one?`) be augmented to return, in the case of a single argument, whether their query holds when each element is supplied to the argument's `#===` method. ## Rationale `Enumerable#grep` filters by case equality, allowing us to write very natural and expressive code: ```ruby strs.select { |str| /foo/ === str } strs.grep(/foo/) nums.select { |num| (5..10) === num } nums.grep(5..10) ``` In addition to taking advantage of the versatility of case equality, it lets us do away with the syntactic noise incurred by opening a block. `#grep` is a very nice method! Let's make `#all?` and friends more like `#grep`. ---Files-------------------------------- 0001-enum.c-add-case-equality-arity-to-sequence-predicates.patch (10 KB) case_equality_sequence_predicates-check_argc_before_deref.patch (10 KB) -- https://bugs.ruby-lang.org/