Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114931 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68968 invoked from network); 17 Jun 2021 14:28:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Jun 2021 14:28:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AFD511804CC for ; Thu, 17 Jun 2021 07:45:44 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from smtp-in.fusiondirectory.org (smtp-in.opensides.be [195.154.20.156]) (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 07:45:44 -0700 (PDT) Received: from smtp-in.fusiondirectory.org (localhost.localdomain [127.0.0.1]) by smtp-in.fusiondirectory.org (Proxmox) with ESMTP id 9BAF6101541 for ; Thu, 17 Jun 2021 16:45:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= fusiondirectory.org; h=cc:content-transfer-encoding:content-type :content-type:date:from:from:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fusiondirectory; bh=0HKEnT3yYF4vwmzG5EBy9K/qk/PHq4cIbjuC8E9p51A=; b=lI+HA7rAwJQL O7EISl62XQ5dZBghNPvuhHKQIJYqZfSOa1fELW0tvfj0PPpHuoCN1wthdUQP/5v9 maBDm0FC77aw41woKeQU5ecqRLmPHmhh1JR++O/m/jaQ49V/Xlj7i2BqZSvJPkwg I4zWYkQn9sFsNs90ZY38mqzFe5ySEyOKodrhuit8b86JGKUZXxQwLI8bwdUrM+BM 80I5U85KGrekc1OOFOWIKW6kqQxcixq38wLABZIz9gEEEKq93Wk8F+X0qTBrgUvM OjuEXQhMNuqc4eV9jYp2ssvW+sDvC9TZkPvJ2mLiLZknprH9XrUtLa3GnKZ6LfIM vWZuZxOv2A== Received: from smtp.fusiondirectory.org (smtp.opensides.be [195.154.20.141]) by smtp-in.fusiondirectory.org (Proxmox) with ESMTP id 5B26A10148F for ; Thu, 17 Jun 2021 16:45:41 +0200 (CEST) Received: from mcmic-probook.opensides.be (63.120.199.77.rev.sfr.net [77.199.120.63]) by smtp.fusiondirectory.org (Postfix) with ESMTPSA id 1F5DB25CB72 for ; Thu, 17 Jun 2021 16:45:41 +0200 (CEST) Date: Thu, 17 Jun 2021 16:45:39 +0200 To: internals@lists.php.net Message-ID: <20210617164539.7b597877@mcmic-probook.opensides.be> In-Reply-To: References: <222b3921-3d9b-47f9-8d13-e6a123f36fad@www.fastmail.com> <20210617095426.7e86bc79@mcmic-probook.opensides.be> Organization: FusionDirectory X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Vote] Partial Function Application From: come.chilliet@fusiondirectory.org (=?UTF-8?B?Q8O0bWU=?= Chilliet) Le Thu, 17 Jun 2021 08:37:23 -0500, "Larry Garfield" a =C3=A9crit : > 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 creat= es a > closure that requires no arguments and will call the original function wi= th > all of the provided values later. This is the "deferred function" use ca= se > mentioned further down. I still do not understand why there is an added variadic parameter when 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, ...); ? > > 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, ...$arg= s]); =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 paramete= rs > > from signature". Here it seems it sometimes mean that, and sometimes me= an > > "accept an additional variadic parameter and pass it along". =20 >=20 > Internally placeholders do mean the former. A trailing variadic, though,= can > accept extra arguments of potentially not pre-defined types, so it sort of > straddles the line. Variadics make things weird. :-) (Dating from PHP > 5.6.) In the majority case, though, thinking of them as "copy the rest of > the arguments" is accurate. I do not understand why Points ...$points becomes untyped ...$args when usi= ng things(...), while when using stuff(...) earlier no typing was lost. C=C3=B4me