Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:125287
X-Original-To: internals@lists.php.net
Delivered-To: internals@lists.php.net
Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5])
	by qa.php.net (Postfix) with ESMTPS id ABD4C1A00BD
	for <internals@lists.php.net>; Mon, 26 Aug 2024 19:12:24 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
	t=1724699657; bh=0FtMsGUuoybQwa4a6YgZOt/52wEEJyR5FZyFCkp4+vw=;
	h=Date:From:Subject:To:Cc:References:In-Reply-To:From;
	b=VZ9BKmFazejSRPxfZJauwivchcM4kxhMJdA8hovhpZkFcQ0N1gUwMjE22q0bXSNhi
	 5+3OUO1XCiP2nWep2HzfjPBoXva1SIE48GUSFxx9IC/6AGWMBljaSICBadLZcJcZV2
	 LhOpYTcSWwXzHfX51HpiUZbQjbMvvVzMtfRecg59TxReEYjc7jcyLomtoOh5TtW5Pp
	 ClJks4fqDcgo4lg2W3EdJMHO8Ak57aQDivibtm4YB8i1IqBdjbhMel2T5GVxG4hM2Y
	 eyduMcLZb8vlikpfD0JYALM2ypMqfaXdF8rHNbU97SbwsR4tBlg8BKR+nzvaGNBoFP
	 1yc9pmj1rrGng==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 90581180054
	for <internals@lists.php.net>; Mon, 26 Aug 2024 19:14:16 +0000 (UTC)
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED,
	DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no
	autolearn_force=no version=4.0.0
X-Spam-Virus: No
X-Envelope-From: <bilge@scriptfusion.com>
Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by php-smtp4.php.net (Postfix) with ESMTPS
	for <internals@lists.php.net>; Mon, 26 Aug 2024 19:14:16 +0000 (UTC)
Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42ab99fb45dso52240585e9.1
        for <internals@lists.php.net>; Mon, 26 Aug 2024 12:12:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1724699542; x=1725304342; darn=lists.php.net;
        h=in-reply-to:content-language:references:cc:to:subject:from
         :user-agent:mime-version:date:message-id:from:to:cc:subject:date
         :message-id:reply-to;
        bh=8A73l2wWoj6+KzCuEOnuj1H3nLuQPM4BMmgMe+btzko=;
        b=pAs9aBvtnPprgBehGmdL6pzzs1ELctCAD6ayykEsV3nx50D5PAlGxK/EdDC5HHM4Hm
         t2S2xDomZ7GF4Bfl/mexyICcX3gijQ5zZCvBSCgEJRIVsYXFKXfzCakbLe/OFNFbwukT
         Z3sIAjFyUNhnpVpM918mhQ8+Y/iZ7/zHC+bu7pTrj4i08x+WGv+lpVYyRw/mMk71dqIk
         Djq/96ouBDrNmVYgAQ/yrgJnH5/7Xd8aKNMNl1LldK94RPcd2qp2cuMNa+DgNu1qG+hf
         c6yjfXZfq51AghX5QvcYN7tzkSHVYAJBTP44x4C4mSmftYGe/rOhIONbMPUOO8jbcVgJ
         wrSQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1724699542; x=1725304342;
        h=in-reply-to:content-language:references:cc:to:subject:from
         :user-agent:mime-version:date:message-id:x-gm-message-state:from:to
         :cc:subject:date:message-id:reply-to;
        bh=8A73l2wWoj6+KzCuEOnuj1H3nLuQPM4BMmgMe+btzko=;
        b=EmnGB61ogp83xYpOIrwxYnZweMAiu/kAL1fNn9nQD3/2KN9EXBR6s5+vDsa6peBpg1
         CCO1rN10LWB5qAeM8kFE85QRhlT/KQ+rDNP2f2A6047Ji+dweQT76XJr3DCPnW64s5no
         hFZDoirXqQh/Yg2GTm88WFZ42EXGjVzxLoGD3QmweOmvSecPt+62diOqpt5BAI81HOMH
         qNFeaL4xTZ/f2b0ByM8s5KGFznn3bXE/N4XMT9TveQYifUMWC9L33Jc13Z7BApT0npZX
         6MGvE30gU1nuY3hcbcnFE13tqf9CBGFBYzYgMXvSDgSs+ebT+d/VqiQoh0C9hOP1VnLh
         yt3g==
X-Gm-Message-State: AOJu0Yxk5RoR99XTKJIZBzgYJ5L3gznouQ3ZvfO6SyVGyGzM4c+T1qY1
	BGPXxeLzP74NnmMW/4Kv+PKq3w1YkMGYtzZkLsx8R+Ip1uP3R/E3uaY2IhxUZ12qnbKdFr2KJj2
	8fLE=
X-Google-Smtp-Source: AGHT+IGUNthR/o8UXcgImuJ2VmVA/JI35hI+9TReEKR2ZNWW/uo8UfAPIGUN6SK44m5MKDiY9a0okg==
X-Received: by 2002:a05:600c:181b:b0:42a:a6b8:f09f with SMTP id 5b1f17b1804b1-42acd5dccd8mr92489985e9.23.1724699541717;
        Mon, 26 Aug 2024 12:12:21 -0700 (PDT)
Received: from ?IPV6:2a01:4b00:bf09:5101:f1f9:cef9:e305:d7f2? ([2a01:4b00:bf09:5101:f1f9:cef9:e305:d7f2])
        by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3730813cdf2sm11388501f8f.38.2024.08.26.12.12.21
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Mon, 26 Aug 2024 12:12:21 -0700 (PDT)
Content-Type: multipart/alternative;
 boundary="------------J4Bdv6kU7sVDi9Ua00le7dck"
Message-ID: <1dbe844c-0ec3-4746-a950-59e9aea36779@scriptfusion.com>
Date: Mon, 26 Aug 2024 20:12:19 +0100
Precedence: bulk
list-help: <mailto:internals+help@lists.php.net
list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net>
list-post: <mailto:internals@lists.php.net>
List-Id: internals.lists.php.net
x-ms-reactions: disallow
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [PHP-DEV] [RFC] Default expression
To: Stephen Reay <php-lists@koalephant.com>
Cc: "internals@lists.php.net" <internals@lists.php.net>
References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com>
 <B37D6F96-092D-4DC0-B100-CBFCCC9AD47E@koalephant.com>
Content-Language: en-GB
In-Reply-To: <B37D6F96-092D-4DC0-B100-CBFCCC9AD47E@koalephant.com>
From: bilge@scriptfusion.com (Bilge)

This is a multi-part message in MIME format.
--------------J4Bdv6kU7sVDi9Ua00le7dck
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

On 26/08/2024 15:20, Stephen Reay wrote:
> Hi,
Hi :)
>
> I haven't followed the entire thread in depth so I apologise if this 
> was already answered, but I haven't noticed it being 
> mentioned/clarified yet.
Don't worry, you're right, this is an important topic that I was still 
finalising in the past 48 hours and is still an omission from the RFC, 
and as such we haven't discussed it on the list yet.
> Can you clarify in the following, is the arm comparing against match's 
> default or the parameter's default? Or to put it another way, in the 
> second call, If `$arg` is 2, will the match error out due to an 
> unmatched subject, or will it pass 1 to `F`?
>
> function F(int $foo =1) {}
>
> F(match(default) {default =>default });
> F(match($arg) {'a' =>0,default =>default });

Thank you for your (excellent) question. The answer is it will pass `1`, 
and the reason is as follows.

`F(match(default) { default => default });` is interpreted as `match 
(default expression) { default arm => default expression }`, therefore 
the first and last `default`s will be substituted with the argument's 
default, but not the middle one. However, that is only the case when the 
default arm is written exactly as `default`.

You can turn the condition into an expression, in which case all three 
will act as expressions and be substituted accordingly, e.g. 
`F(match(default) { (int) default => default });`.

Since the default condition is now an expression, you can still have a 
default arm in addition to this, e.g. the following would be valid:

F(match(default) {
     (int) default => default,
     default => default,
});

Whilst this is a curiosity, consider that passing match expressions 
directly to arguments is something I personally have never witnessed and 
that goes doubly for combining it with `default`. So, whilst it is 
interesting to know, and important for the RFC to state the specific 
semantics of this scenario, the practical applications are presumed slim 
to none.

Cheers,
Bilge

--------------J4Bdv6kU7sVDi9Ua00le7dck
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">On 26/08/2024 15:20, Stephen Reay
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:B37D6F96-092D-4DC0-B100-CBFCCC9AD47E@koalephant.com">
      <div>Hi,</div>
    </blockquote>
    Hi :)<br>
    <blockquote type="cite"
      cite="mid:B37D6F96-092D-4DC0-B100-CBFCCC9AD47E@koalephant.com">
      <div><br>
      </div>
      <div> <font color="#000000"><span
            style="caret-color: rgb(0, 0, 0);">I haven't followed the
            entire thread in depth so I apologise if this was already
            answered, but I haven't noticed it being mentioned/clarified
            yet.</span></font></div>
    </blockquote>
    Don't worry, you're right, this is an important topic that I was
    still finalising in the past 48 hours and is still an omission from
    the RFC, and as such we haven't discussed it on the list yet.<br>
    <blockquote type="cite"
      cite="mid:B37D6F96-092D-4DC0-B100-CBFCCC9AD47E@koalephant.com">
      <div>Can you clarify in the following, is the arm comparing
        against match's default or the parameter's default? Or to put it
        another way, in the second call, If `$arg` is 2, will the match
        error out due to an unmatched subject, or will it pass 1 to `F`?</div>
      <div><br>
      </div>
      <div>
        <div
style="background-color: rgb(255, 255, 255); color: rgb(75, 77, 85);">
          <pre
style="font-family: &quot;JetBrains Mono&quot;, monospace; font-size: 9.8pt;"><span
          style="color: rgb(174, 93, 52);">function </span><span
          style="color: rgb(28, 130, 227);">F</span>(<span
          style="color: rgb(174, 93, 52);">int </span><span
          style="color: rgb(155, 112, 177);">$foo </span>= <span
          style="color: rgb(97, 255, 255);">1</span>) {}

<span style="color: rgb(25, 129, 225);">F</span>(<span
          style="color: rgb(174, 93, 52);">match</span>(<span
          style="color: rgb(174, 93, 52);">default</span>) { <span
          style="color: rgb(174, 93, 52);">default </span>=&gt; <span
          style="color: rgb(174, 93, 52);">default </span>})<span
          style="color: rgb(167, 172, 181);">;
</span></pre>
          <pre
style="font-family: &quot;JetBrains Mono&quot;, monospace; font-size: 9.8pt;"><span
          style="color: rgb(167, 172, 181);">
</span></pre>
          <pre
style="font-family: &quot;JetBrains Mono&quot;, monospace; font-size: 9.8pt;"><div
          style="white-space: normal;"><pre
style="font-family: &quot;JetBrains Mono&quot;, monospace; font-size: 9.8pt;"><span
          style="color: rgb(25, 129, 225);">F</span>(<span
          style="color: rgb(174, 93, 52);">match</span>(<span
          style="color: rgb(155, 112, 177);">$arg</span>) { <span
          style="color: rgb(100, 181, 111);">'a' </span>=&gt; <span
          style="color: rgb(97, 255, 255);">0</span>, <span
          style="color: rgb(174, 93, 52);">default </span>=&gt; <span
          style="color: rgb(174, 93, 52);">default </span>})<span
          style="color: rgb(167, 172, 181);">;</span></pre></div></pre>
        </div>
      </div>
    </blockquote>
    <p> Thank you for your (excellent) question. The answer is it will
      pass `1`, and the reason is as follows.</p>
    <p>`F(match(default) { default =&gt; default });` is interpreted as
      `match (default expression) { default arm =&gt; default expression
      }`, therefore the first and last `default`s will be substituted
      with the argument's default, but not the middle one. However, that
      is only the case when the default arm is written exactly as
      `default`.</p>
    <p>You can turn the condition into an expression, in which case all
      three will act as expressions and be substituted accordingly, e.g.
      `F(match(default) { (int) default =&gt; default });`.</p>
    <p>Since the default condition is now an expression, you can still
      have a default arm in addition to this, e.g. the following would
      be valid:<br>
      <br>
      F(match(default) {<br>
          (int) default =&gt; default,<br>
          default =&gt; default,<br>
      });</p>
    <p>Whilst this is a curiosity, consider that passing match
      expressions directly to arguments is something I personally have
      never witnessed and that goes doubly for combining it with
      `default`. So, whilst it is interesting to know, and important for
      the RFC to state the specific semantics of this scenario, the
      practical applications are presumed slim to none.</p>
    <p>Cheers,<br>
      Bilge<br>
    </p>
  </body>
</html>

--------------J4Bdv6kU7sVDi9Ua00le7dck--