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-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no 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 EB0B71F66F for ; Thu, 29 Oct 2020 05:07:31 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 85504120B47; Thu, 29 Oct 2020 14:06:48 +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 EE0F1120B46 for ; Thu, 29 Oct 2020 14:06:46 +0900 (JST) Received: by filterdrecv-p3mdw1-5b99b59cbc-wlh97 with SMTP id filterdrecv-p3mdw1-5b99b59cbc-wlh97-19-5F9A4E07-20 2020-10-29 05:07:19.520073199 +0000 UTC m=+188822.223215336 Received: from herokuapp.com (unknown) by ismtpd0018p1iad2.sendgrid.net (SG) with ESMTP id riPvC2NcTgiTJP4ir0bAeA for ; Thu, 29 Oct 2020 05:07:19.436 +0000 (UTC) Date: Thu, 29 Oct 2020 05:07:19 +0000 (UTC) From: keystonelemur@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76507 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17292 X-Redmine-Issue-Author: baweaver X-Redmine-Sender: baweaver 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?XlD0LGPYDDjb=2FA1CQKGKXgvLTTlhHMIrQD1g5Sx7EbI98Iv1v0K+gVm+gv1Dv+?= =?us-ascii?Q?cbufjoLVOE+y04NugvmYQ4=2FT5hW1WPdImajK3ts?= =?us-ascii?Q?nGpdzFwXl2tRkFnXEslgv5RqndTT7UWT2o9139J?= =?us-ascii?Q?ju8S5Ap4nYAMBEnEfNY90OS41CO1KpqxYaF2k82?= =?us-ascii?Q?moH0FLj3c8xfjm5M=2F=2FmG+i503b1PuMptvVibewe?= =?us-ascii?Q?78KcUdEWeYuQbrXPI=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100635 Subject: [ruby-core:100635] [Ruby master Feature#17292] Hash Shorthand / Punning 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="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17292 has been reported by baweaver (Brandon Weaver). ---------------------------------------- Feature #17292: Hash Shorthand / Punning https://bugs.ruby-lang.org/issues/17292 * Author: baweaver (Brandon Weaver) * Status: Open * Priority: Normal ---------------------------------------- ### Set Literal vs Javascript Object Punning There was a proposal for a Set literal here: https://bugs.ruby-lang.org/issues/16989 ```ruby set = { 1, 2, 3 } ``` ...but it was brought up that this is similar to the Javascript Object punning, or Object shorthand syntax: ```js const a = 1, b = 2, c = 3; const punnedObject = { a, b, c } // => { a: 1, b: 2, c: 3 } ``` **Proposition**: I believe we should use brackets (`{}`) for a shorthand Hash syntax similar to Javascript. ### Hash Punning My first proposal in this feature request is Hash punning, or Hash shorthand: ```ruby a = 1 b = 2 c = 3 { a:, b:, c: } # => { a: 1, b: 2, c: 3 } ``` This syntax avoids the ambiguous syntax of empty block (`{}`) versus empty set (`{}`), and with the presence of Symbols it introduces a distinct syntax that would be easier to parse against. One potential issue would be mixed syntax: ```ruby { a:, b: 2 } # => { a: 1, b: 2 } ``` ### Method Punning This syntax can also be used for keyword argument and method call punning: ```ruby def method_name(a:, b:, c:) a + b + c end a = 1 b = 2 c = 3 method_name(a:, b:, c:) # => 6 ``` I believe this existing syntax for required keywords gives credence to the idea of introducing punning to Ruby, as it's very similar to existing syntax, and therefor feels "Ruby-like". ### Pattern Matching This syntax is also already present and used in pattern matching, making it already part of the language: ```ruby case { x: 1, y: 2 } in { x:, y: } { x:, y: y + 1} # new else # ... end ``` I believe this further justifies the case for punning syntax. -- https://bugs.ruby-lang.org/