Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112537 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96286 invoked from network); 17 Dec 2020 16:52:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Dec 2020 16:52:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5FDB61804F3 for ; Thu, 17 Dec 2020 08:24:01 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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, 17 Dec 2020 08:24:00 -0800 (PST) Received: by mail-lf1-f47.google.com with SMTP id m12so58861417lfo.7 for ; Thu, 17 Dec 2020 08:24:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wRQDo6R9uUpZ9lCdB2qnB0NssdGkCOWqFq4VqQUUlz8=; b=qQDP+5zh0kdeisNJ7ojlx241rGlhMs+0z25Z9ABEt/8q72Ubk9L1RKnB86X4r6YPCc kzJKPLb+ueG2Yq/Rxp3h0f3SMk+5lSrB08zW4h5ztFK1TmpPICNWR9uS0mX77U/ACnpa 2yTGQvWt6p/453l6X+1rM7Xjmvq3ekmA8EhTRsIm034UFHKmCxCzpAzJclJSSInzbMkb QSVXc7L/Y/sNf0aNLGZjrrEWzKULWxcLE8bKhteyo4q2SVpf4CpeMrvxDnW36Tw/iyc8 y2rGdo7u7YG3Xg4sFdB/i204r1pCTNp2rq+cQL2H+LOIg9XT2gUyO2ET9ABsQaX/KeeO fsSw== X-Gm-Message-State: AOAM533ykZcGbYsXE1ipqz98I6FjbM045yTinEYcL0US5SMA0vurd2bZ 8uiz2DApDSq72S18kPkTZTBUERyl3ePU97/17uyNzw== X-Google-Smtp-Source: ABdhPJx2hh/ZuMUu6mCqKFFUhtxne9TwYRneEcURF4LJ6iURLa7pj8qVZ1izVVZ08EZR7GbBDjgLh2GdPnvFkPGRXX8= X-Received: by 2002:a2e:9f14:: with SMTP id u20mr44377ljk.244.1608222234376; Thu, 17 Dec 2020 08:23:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 17 Dec 2020 10:23:43 -0600 Message-ID: To: someniatko Cc: Marco Pivetta , Larry Garfield , php internals Content-Type: multipart/alternative; boundary="00000000000000419005b6ab6b8b" Subject: Re: [PHP-DEV] [RFC] Short-match From: pollita@php.net (Sara Golemon) --00000000000000419005b6ab6b8b Content-Type: text/plain; charset="UTF-8" On Wed, Dec 16, 2020 at 6:50 PM someniatko wrote: > > `match` is an expression, where as if-else construction is not. This > allows for combining it with a potential future feature of single line > functions and methods. For example (hypothetical syntax is used): > > ``` > $getNumber = fn(int $number) => match { > $number < 0 => NumberKind::NEGATIVE, > $number == 0 => NumberKind::ZERO, > $number > 0 => NumberKind::POSITIVE, > }; > ``` > That does read attractively, yes. This is the example that should have been offered first as it shows the expression nature shining. To contrast that with what would be possible now in an expressive functional form: $getNumber = fn(int $number) => [ -1 => NumberKind::NEGATIVE, 0 => NumberKind::ZERO, 1 => NumberKind::POSITIVE, ][$number <=> 0]; The match form *certainly* reads more naturally than the spaceship indexing form even though both take up equal space. -Sara --00000000000000419005b6ab6b8b--