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 5ECA619C0020 for ; Fri, 23 Oct 2015 01:09:37 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id C8EECB5D874 for ; Fri, 23 Oct 2015 01:36:48 +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 CBAD4952439 for ; Fri, 23 Oct 2015 01:36:46 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 87C581204C2; Fri, 23 Oct 2015 01:36:46 +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 6BA391204B3 for ; Fri, 23 Oct 2015 01:36:42 +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=N2J2Il4aDDkj4WGWAQa1zzvl8bc=; b=q9/Ui1wqs5jwT0LlTA SlkANJd6kFCEvE40MOQ7AhTsedoH+W86TjDaAXdAjI3RMf5WGT5Q8WI+Ho7Yp+x1 7eKNHYweIJSIx5/13cATeOwp+SmA10eXOsao2rZcaJf9uVqHgXxPxCVot6vDq1EG MmvN/JV4fTW/DR3F4/al3eJpw= Received: by filter0086p1mdw1.sendgrid.net with SMTP id filter0086p1mdw1.14149.5629100DF 2015-10-22 16:34:21.231559879 +0000 UTC Received: from herokuapp.com (ec2-54-198-211-117.compute-1.amazonaws.com [54.198.211.117]) by ismtpd0006p1iad1.sendgrid.net (SG) with ESMTP id 6hfR3LxbTQO0fsKxGwnWbw for ; Thu, 22 Oct 2015 16:34:21.062 +0000 (UTC) Date: Thu, 22 Oct 2015 16:34:21 +0000 From: ary@esperanto.org.ar 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: 45784 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11537 X-Redmine-Issue-Author: hsbt X-Redmine-Issue-Assignee: matz X-Redmine-Sender: asterite 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS6MDuQAPqlTRKrQhXNo6wTD4YKwjA4i+6ilR0 iy2FvsV9HnBa349hkuBx46Xbk+SL2UbQ25x/Zfv9Q4Nf7GHoEz7qhCAW1kc9EX0u2QDuXvgEXxU2sL b071dxpKeBwpVnDyFJY80cNdHY2dqeYnHPu9 X-ML-Name: ruby-core X-Mail-Count: 71158 Subject: [ruby-core:71158] [Ruby trunk - Feature #11537] Introduce "Safe navigation operator" 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 #11537 has been updated by Ary Borenszweig. I know this is already decided and the commit is out there, but since you are adding new syntax and a new feature to the language, I suggest you reconsider https://bugs.ruby-lang.org/issues/9076 With that change, instead of adding special syntax for safe nil traversing, you get generalized syntax for the implicit block argument. Instead of this: ``` obj.?bar(x, y) ``` You do: ``` obj.try &.bar(x, y) ``` The `try` method is simply: ``` class Object # But obviously implemented in C for performance reasons def try yield self unless self.is_a?(NilClass) end end ``` As I mention in the original issue, `foo &.bar` simply gets translated *by the parser* to something like `foo { |x| x.bar }` (where `x` doesn't conflict with any other identifier in the method). So it's just a change in the parser, no need to change compile.c, insns.def, etc (although I can understand that nil checking might be optimized with a VM instruction). My main worry is code like this: ``` obj.?empty? ``` That looks confusing to the eye. I associate "?" next to method names to "query" methods, and now when reading an expression "?" can have several meanings (in addition to the ternary operator). We already have this syntax in [Crystal](http://www.crystal-lang.org) and it's working really well. ---------------------------------------- Feature #11537: Introduce "Safe navigation operator" https://bugs.ruby-lang.org/issues/11537#change-54531 * Author: Hiroshi SHIBATA * Status: Closed * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- I sometimes write following code with rails application: ```ruby u = User.find(id) if u && u.profile && u.profile.thumbnails && u.profiles.thumbnails.large ... ``` or ```ruby # Use ActiveSupport if u.try!(:profile).try!(:thumbnails).try!(:large) ... ``` I hope to write shortly above code. Groovy has above operator named "Safe navigation operator" with "`?.`" syntax. Ruby can't use "`?.`" operator. Can we use "`.?`" syntax. like this: ```ruby u = User.find(id) u.?profile.?thumbnails.?large ``` Matz. How do you think about this? -- https://bugs.ruby-lang.org/