Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114932 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75795 invoked from network); 17 Jun 2021 15:34:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Jun 2021 15:34:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 092501804CC for ; Thu, 17 Jun 2021 08:51:28 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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 Jun 2021 08:51:27 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 488105EC for ; Thu, 17 Jun 2021 11:51:26 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute3.internal (MEProxy); Thu, 17 Jun 2021 11:51:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=TG4Nl21AUeo6XNRKc+P/jtlQ8Se1ITolid3O4peY3 qA=; b=FZNvu0Fl2EdxVWu6v0wfC82bG7mgtj5m9IUoJJptWSqfjvoC0RJ/cLdtd 9flPtmbpUnLYiSPccQasLFWIYFZ9I0BZArG+MG4XyLK1rkIX4hx8mVbEVm8zlp6P UbxHeZsZQQdBDi3KjYrmg8gAT63qdW7euN355sOfjo0PtUEVAHxGENyKkMmNTgGS S5THCpZz4CzIAa2beWPaWwKNZGpg3h3vHAa5jb3GzdOEmpmbVlEhSTKu5m5GvEAW fNfTYwXf2Txm7Fr1lBNvwpTN/EdQ3NoBmbOhMO1BtdLLVLpTDMvHE1gKUbv5Pwsn wCZAW7fPmFNFonXBtKZ/3fG5Rh1CA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeefuddgledvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9B1BF3A0430; Thu, 17 Jun 2021 11:51:25 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-526-gf020ecf851-fm-20210616.001-gf020ecf8 Mime-Version: 1.0 Message-ID: In-Reply-To: <20210617164539.7b597877@mcmic-probook.opensides.be> References: <222b3921-3d9b-47f9-8d13-e6a123f36fad@www.fastmail.com> <20210617095426.7e86bc79@mcmic-probook.opensides.be> <20210617164539.7b597877@mcmic-probook.opensides.be> Date: Thu, 17 Jun 2021 10:51:00 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Vote] Partial Function Application From: larry@garfieldtech.com ("Larry Garfield") On Thu, Jun 17, 2021, at 9:45 AM, C=C3=B4me Chilliet wrote: > Le Thu, 17 Jun 2021 08:37:23 -0500, > "Larry Garfield" a =C3=A9crit : >=20 > > On Thu, Jun 17, 2021, at 2:54 AM, C=C3=B4me Chilliet wrote: > > > > $c =3D stuff(...); > > > > $c =3D fn(int $i, string $s, float $f, Point $p, int $m =3D 0) =20= > > > > =3D> stuff($i, $s, $f, $p, $m); =20 > > > =20 > > > > $c =3D stuff(1, 'hi', 3.4, $point, 5, ...); > > > > $c =3D fn(...$args) =3D> stuff(1, 'hi', 3.4, $point, 5, ...$args= ); =20 > > >=20 > > > Why is there an additional variadic parameter in this one? =20 > >=20 > > ... means "zero or more". In this case, it means zero, that is, it = creates a > > closure that requires no arguments and will call the original functi= on with > > all of the provided values later. This is the "deferred function" u= se case > > mentioned further down. >=20 > I still do not understand why there is an added variadic parameter whe= n > using ... in stuff(1, 'hi', 3.4, $point, 5, ...); but not when using = it in > stuff(...); > What happens when we use stuff(1, 'hi', 3.4, $point, ...); ? >=20 > > > Also, in the second set of examples: =20 > > > > function things(int $i, float $f, Point ...$points) { ... } =20 > > > =20 > > > > // Ex 13 > > > > $c =3D things(...); > > > > $c =3D fn(int $i, float $f, ...$args) =3D> things(...[$i, $f, ..= .$args]); =20 > > > =20 > > > > // Ex 14 > > > > $c =3D things(1, 3.14, ...); > > > > $c =3D fn(...$args) =3D> things(...[1, 3.14, ...$args]); =20 > > >=20 > > > What happens to the typing of the variadic parameter here? Why is = it > > > removed? > > >=20 > > > It would feel natural that the ... means "copy the rest of the par= ameters > > > from signature". Here it seems it sometimes mean that, and sometim= es mean > > > "accept an additional variadic parameter and pass it along". =20 > >=20 > > Internally placeholders do mean the former. A trailing variadic, th= ough, can > > accept extra arguments of potentially not pre-defined types, so it s= ort of > > straddles the line. Variadics make things weird. :-) (Dating from = PHP > > 5.6.) In the majority case, though, thinking of them as "copy the r= est of > > the arguments" is accurate. >=20 > I do not understand why Points ...$points becomes untyped ...$args whe= n using > things(...), while when using stuff(...) earlier no typing was lost. The type information is not lost. The examples are not exact equivalent= s, but approximate equivalents. Joe confirmed that the closure that's g= enerated really does retain the type information: krakjoe@Fiji:/opt/src/php-src$ cat wat.php partial function things ] { @@ /opt/src/php-src/wat.php 4 - 4 - Parameters [3] { Parameter #0 [ int $i ] Parameter #1 [ float $f ] Parameter #2 [ Point ...$points ] } } --Larry Garfield