Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112540 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2197 invoked from network); 17 Dec 2020 17:08:13 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Dec 2020 17:08:13 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0985F180503 for ; Thu, 17 Dec 2020 08:39:42 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_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-Virus: No X-Envelope-From: Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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:39:41 -0800 (PST) Received: by mail-ed1-f43.google.com with SMTP id q16so29274934edv.10 for ; Thu, 17 Dec 2020 08:39:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=2kiBAk0NSLVkKKW8GCg/xjp3VQ70qMmiAQto4vi1N/Q=; b=tZlOYgp3dRVttF20Kqs/QdRtyDEvfCApOwMeTq/QBn6yr0ASS4yvxCtgrzoeOyZhMV SHKmaCCwCtH7pTlHki2D71yeIQ0vWUDybvMay0V3BFlr8XV3m0Vkr2Pf7bxFf3gn6iuc 6tv0mxRUqR6mMxHqWPEPDxlK5KP/4GsT7ia+8I/ESWkk4V4PrezWQiFLIUzFR0SXdmZ+ egAoyhDLXicbS00O7wuC9/OqVIwU5TSB5OSSqm9vLXdyV6SGO9TCsoA3u1gSI3huBywO h8RN9TErIzbPhwWZQEPzPFexbWC6t7+MqLho1uWkjbxTowskTsld0JJc4VoQ74EdgF/W S5rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=2kiBAk0NSLVkKKW8GCg/xjp3VQ70qMmiAQto4vi1N/Q=; b=B+KIJjtzyKebPlyLjsg17CZk3d4hxpCIEWYCkQnYydePOXdaZ1YBd3Tb2kTxhnffhJ TdOvTM8EngS1BCbK8ItS8Wrqyd4CSpz4H96OuonykKgpdzJMxKF6KMqQImld28PUec30 FdjrzNsPW3GNUlTAVaLYdgAZlwaEvf8QgBFStqwUjJVjECAVM/pTIu+j1gcSWmVL4GgS K0XlXZDlBKx3e0ZeC//lvuJMOM4tUGprBEltq6m6doh2YP/oqH73/XV/1I4QnIKOR7B4 gYxEco/LaA38+TPWpmYDcI5AN2hT/BfPs8Z5lVMd/+vAScIbXZUta61/gMZ9JMWCqayr a+9g== X-Gm-Message-State: AOAM532MS1fnx/30d5qpRaxRlc+E6dCw1rLHwl3D2m+W/ecak/xKQI6t 82cuoOEEE96oiaYts35PMG3d3uninuN+bA== X-Google-Smtp-Source: ABdhPJxXqsDOVyyhWa5e/TCdLghDkfJsyywt1RPz+uFcp3Zlu/WrIW/tb+qJeuT9j5CzMTC/A4QOlA== X-Received: by 2002:aa7:c84c:: with SMTP id g12mr149812edt.193.1608223179651; Thu, 17 Dec 2020 08:39:39 -0800 (PST) Received: from claude.fritz.box ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id r24sm23951105edc.21.2020.12.17.08.39.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Dec 2020 08:39:38 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) In-Reply-To: Date: Thu, 17 Dec 2020 17:39:37 +0100 Cc: someniatko , Marco Pivetta , Larry Garfield , php internals Content-Transfer-Encoding: quoted-printable Message-ID: <7748CD30-5972-4130-9FFE-C31E8C0D405B@gmail.com> References: To: Sara Golemon X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Short-match From: claude.pache@gmail.com (Claude Pache) > Le 17 d=C3=A9c. 2020 =C3=A0 17:23, Sara Golemon a = =C3=A9crit : >=20 > On Wed, Dec 16, 2020 at 6:50 PM someniatko = wrote: >>=20 >> `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): >>=20 >> ``` >> $getNumber =3D fn(int $number) =3D> match { >> $number < 0 =3D> NumberKind::NEGATIVE, >> $number =3D=3D 0 =3D> NumberKind::ZERO, >> $number > 0 =3D> NumberKind::POSITIVE, >> }; >> ``` >>=20 >=20 > That does read attractively, yes. This is the example that should = have > been offered first as it shows the expression nature shining. >=20 > To contrast that with what would be possible now in an expressive > functional form: >=20 > $getNumber =3D fn(int $number) =3D> [ > -1 =3D> NumberKind::NEGATIVE, > 0 =3D> NumberKind::ZERO, > 1 =3D> NumberKind::POSITIVE, > ][$number <=3D> 0]; >=20 > The match form *certainly* reads more naturally than the spaceship = indexing > form even though both take up equal space. >=20 > -Sara If you mean a version of `if` that works in expressions, there already = exists a standard operator for that. Once its historical associativity = goof is definitely fixed, you will be able to write: ``` $getNumberKind =3D fn(int $number) =3D> $number > 0 ? NumberKind::POSITIVE : $number =3D=3D 0 ? NumberKind::ZERO : $number < 0 ? NumberKind::NEGATIVE : throw new \TypeError; ``` There is a semantic advantage of `match` over `? : `, though, namely its = exhaustivity: You don=E2=80=99t need to add a =E2=80=9Cpanic=E2=80=9D = default case in order to catch logic errors. =E2=80=94Claude=