Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109822 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89850 invoked from network); 24 Apr 2020 04:50:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Apr 2020 04:50:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2A4981804B4 for ; Thu, 23 Apr 2020 20:22:18 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HK_RANDOM_ENVFROM,HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 23 Apr 2020 20:22:14 -0700 (PDT) Received: by mail-lf1-f48.google.com with SMTP id g10so6437482lfj.13 for ; Thu, 23 Apr 2020 20:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=AoT8EJp4mz/KsGgZtgWey2oYsTs/iN0tAlztSUKSRrA=; b=aDgnJoDwvX+38q97t94RSf5/kvxJz49wM0mHK0P8gNM4N3oT8I1WdmiLIvjoQpYPw4 ic1GDMxLyhgNeA2+f44SG39roKBndqrbb234c5XudJmPJLsFM5fZKxPplKrMTHwwQOzo sSOUYSCOaoKG8VaOAyIfjry+rqAe7j8dtLB4C7o5pumxMvwPlYvGVxWjQSP7UUF0k9fQ XR1UJktmpdpTxoNdE6+hCie0v7V2M6dwGDs9hYAbD+6XWQv4eK9BvP3EBRdAD9Vdfafd h4Ln6Vba6fDmNFvqB9KeIAzbdG8dRn5u5dJ3zu7CS5bQ4L5J+GEvWtD+DWSEUNXxQQq5 Cf9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=AoT8EJp4mz/KsGgZtgWey2oYsTs/iN0tAlztSUKSRrA=; b=Lb7RYEDIMtyt+/J0S5kZG/9hdGZG0MEzBP3mWvs1c8wdmq6WRb/4x6q81xyY7OKCr5 74WaJEGTY86GVSBF55brp8XqwPXAnemSYupTqOpO3w7Rtm2TDLwszIZr8Gmge8h/vcaj vCRtev9put3IVuAmT2i+3XkLXII0EiRBhen4wxQB7fh5Eq9wx1WjaQh8naNplqZGmnvb u92Ux3IxtEQAiNZ6ADWW7jvYlK+uqY7hGHiiCKMVHPUqr2lXB3y+oyqAL+zbkFu2Q3++ 7AGCirXv1uPb/b3i9p2sjQa5cUVuaTMt7PFzPmXo3pofU94bLrO/FTd+dbLRjXI+oxG1 OxvQ== X-Gm-Message-State: AGi0PuaTKOLu7u7zpA2Wl1oPuH+8Jpu8Q21nGqlT9chR+tO8hhmVknye IvF0VCMSKMN8ra2uC/UWNMUgeCu9 X-Google-Smtp-Source: APiQypKfF84xZElLBCF7YAQO0/BLyHKaX7UNFH4lNy25YXxwNRzrqJWiBR8xq0tQYi5tUAcAyeMoxQ== X-Received: by 2002:ac2:489b:: with SMTP id x27mr4675116lfc.60.1587698532670; Thu, 23 Apr 2020 20:22:12 -0700 (PDT) Received: from [192.168.1.118] (host-195-80-128-245.wtvk.pl. [195.80.128.245]) by smtp.gmail.com with ESMTPSA id v17sm3383601lfi.49.2020.04.23.20.22.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Apr 2020 20:22:12 -0700 (PDT) To: internals@lists.php.net References: <5e9abc70-a958-7bde-b369-d20260cc95e0@gmail.com> Message-ID: Date: Fri, 24 Apr 2020 05:22:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <5e9abc70-a958-7bde-b369-d20260cc95e0@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [PHP-DEV] [DISCUSSION] Match expression From: hubertnnn@gmail.com (HubertNNN) > Hi! > >> I'm not quite sure what the way forward regarding that is. I can understand >> the reluctance to propose the Rust-style block expression syntax, given its > Speaking of which, what is the problem with that? I mean, if we just > declare that the value of a block is the return of the last expression, > would it break anything? Of course, by itself it'd be useless since we > still aren't using blocks as expressions. But if we then had constructs > that could accept both blocks and expressions - and we don't need to > make everything that accepts expressions to accept blocks - we just need > to make it make sense in those "dual" constructs. > I think that introducing a new construct like that would require its own RFC Especially since there is a lot of confusion around how those blocks should work. Eg. why should the fact that I use or not a semicolon depend on the fact what I will do with return value of the expression. I think a much more sane solution would be to only allow expressions in match. $x = match(true) {     $a === 1 => foo(),     $b > 2 => bar(), } $a = match($a) {     1 => foo(),     2 => bar(), } And then a block could be just an alias for a self calling anonymous function with all of its consequences: - continue and break forbidden - return being the keyword used to match the result instead of missing semicolon - if no return was provided result defaults to null - etc. eg. this two are equal statements assigning result of baz() to $y: $y = match($x) {     1 => {         foo();         bar();         return baz();     },     ... } $y = match($x) {     1 => function() use(everything) {         foo();         bar();         return baz();     }(),     ... } Also I think that suggestion that someone already made about making the parameter default to true is a really god idea, I even believe that statements in this form are probably going to be more common than the standard one: $y = match {     $a < 10 => foo(),     $a < 20 => bar(),     ... }