From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 179CC1F4B4 for ; Sat, 10 Apr 2021 03:20:49 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2BDDE120CBC; Sat, 10 Apr 2021 12:19:47 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 15877120CBB for ; Sat, 10 Apr 2021 12:19:44 +0900 (JST) Received: by filterdrecv-c5749c756-z7g7k with SMTP id filterdrecv-c5749c756-z7g7k-15-60711986-32 2021-04-10 03:20:38.968756057 +0000 UTC m=+1333011.223781500 Received: from herokuapp.com (unknown) by ismtpd0167p1mdw1.sendgrid.net (SG) with ESMTP id AGkyLqbZQqyb8KKIjHf_GA for ; Sat, 10 Apr 2021 03:20:38.914 +0000 (UTC) Date: Sat, 10 Apr 2021 03:20:39 +0000 (UTC) From: nobu@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79409 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17785 X-Redmine-Issue-Author: marcandre 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: =?us-ascii?Q?q8Dly+pU2+3ektTtZVXgZtbJPXwqo7p86jCsvYTW4Bx9zsyQhNbOoJ0TVmQY+o?= =?us-ascii?Q?r8ugqfRhj6V6JVbTES0e+7Z1YX0sD+PzL9ywpP1?= =?us-ascii?Q?1CasuVh9EXEtVooPx5B10E4vvGwhIrAsV2nBKy8?= =?us-ascii?Q?t8doM7diw5RS8jAdV94kHmBl4UQ9+X2Zs3AOtRk?= =?us-ascii?Q?0fYv=2FFaCZCoVNw6+P551t805Sc=2FZVVWtnEQ=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103362 Subject: [ruby-core:103362] [Ruby master Feature#17785] Allow named parameters to be keywords 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: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17785 has been updated by nobu (Nobuyoshi Nakada). duerst (Martin D=FCrst) wrote in #note-7: > What about finding something in between the two? E.g. even just introduci= ng `variable_get` as an alias to `binding.local_variable_get` would make th= is easier to use. And if this really needs optimization, it could be done, = too, but using a different argument name would solve the problem. In built-in methods written in Ruby, we chose `__builtin.arg!(:in)` form (s= ee timve.rb). > With respect to `\`, it reminds me of older languages (such as m4, C, and= TeX) where there's a purely string-based level below (or before) the usual= structured syntax. Do we want Ruby to descend to that level? Escaping exis= ts inside strings because you don't want the range of data you can handle w= ith a programming language to be restricted by the syntax of the language i= tself. Also, escaping inside strings is frequent enough for everybody, and = occurs in a very similar form across a wide range of programming languages,= so that every programmer knows it. Backslashes in front of keywords would = be a whole different matter. Agree, and backslashes will be troublesome in `eval` obviously. ---------------------------------------- Feature #17785: Allow named parameters to be keywords https://bugs.ruby-lang.org/issues/17785#change-91453 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- We should allow named parameters to be keywords and use add a trailing `_` = to the corresponding variable: ```ruby def check(arg, class:) arg.is_a?(class_) end check(42, class: Integer) # =3D> true ``` Currently, if we want such an API we have to use `**rest`: ```ruby def check(arg, **rest) class_ =3D rest.fetch(:class) { raise ArgumentError('missing keyword: :cl= ass')} if rest.size > 1 unknown =3D rest.keys - [:class] raise ArgumentError("unknown keyword(s): :#{unknown.join(', :')}) end arg.is_a?(class_) end ``` This is very verbose, much less convenient, much less readable, prevents `s= teep` from generating the proper signature, etc. We should do the same for pattern match. -- = https://bugs.ruby-lang.org/ Unsubscribe: