Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114487 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86952 invoked from network); 16 May 2021 13:37:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 May 2021 13:37:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 11CEB180211 for ; Sun, 16 May 2021 06:46:27 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 ; Sun, 16 May 2021 06:46:26 -0700 (PDT) Received: by mail-qk1-f169.google.com with SMTP id x8so3426947qkl.2 for ; Sun, 16 May 2021 06:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=4BDGk49gOvwei1mdEZtcPJNI9iZUGsYgFRhBHoEfMMs=; b=tuqltqeSXgupAoJIO0obuChsdZm6BBo4e3SPh1tR+NY1cCsTCXJ/KO08Vru8pYe4nW SfyRTHJkduzbgzvQfZXEaZTrxPTRphpi36WKMVYvLKjPDHBV+6lSWAka9FaRf5g+10Bh bfT2C/TYvsV0+lW5qzZIvV3zJ9RJrxyXHJ7Jd33p6dKjDU/ElWolvWvSZh61RS7U4b1u iB7kMFyylkGEPMSPs36/PzAbq+TBBpuq6xncp66v8RbQR+aN/QAQdj4xvRWDkHYT6i0w NxPFS96WkkXz0tRO63s9WQ5GA6FnzgiQ8mw1nMM460A24BE4ViCn5M5Bxx7LuLlDG1gi XBAA== 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=4BDGk49gOvwei1mdEZtcPJNI9iZUGsYgFRhBHoEfMMs=; b=LPvbNfLypn0QPAn8IbRpt2GJYvnolRcWRWicNCxq9EvEEoSrh38C+k9bXhSgUZkcJW 0TVoN/xo4OAt4cf7z8TcZhJaR3OZdLk6pdd528PLY6TOfg4d5xL9cE15qoxRx+YUvjc0 hV16E6u68STmAhrNgM8j9XQC0C/oTCDNU2S1YogMfmXwUbiFGO+vQRjwjIC6irEwIShw me0DG5W81e0SAiT0bFEpvGap4v2LZLeMvuPu0Qn86nIVGNOmy2HYBBhgB5wGkKusD8Ra Knhdrrv3zyuWLgBdYnjNJlbmP+rLl6b2rsoqHLZc141d/xkL4jWgn0r6ZtrNDSkcHR8B /M/A== X-Gm-Message-State: AOAM532SyDthX5iIcnpGQ2uYwq0nouFUC7eUs7Sz/bLx274VqqS08Dso tJ4TgfcCE5gkU/IjPXHVjcIGcg== X-Google-Smtp-Source: ABdhPJzqxzbB7rB3cbdlFudIGYwtqTt1SJyzYZ/JAzpAHmfJoPA5Er5UF8AVQ3w8sNZaTriHRXzGJQ== X-Received: by 2002:a05:620a:10:: with SMTP id j16mr51557542qki.137.1621172785601; Sun, 16 May 2021 06:46:25 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id t18sm8245251qtn.63.2021.05.16.06.46.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 May 2021 06:46:24 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.6\)) In-Reply-To: <912F2203-FCEF-441E-9272-65624F4C0FDB@gmail.com> Date: Sun, 16 May 2021 09:46:22 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <1565EB81-57B7-49B0-A47C-342E0088A432@trowski.com> <912F2203-FCEF-441E-9272-65624F4C0FDB@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.6) Subject: Re: [PHP-DEV] [RFC] Partial function application From: mike@newclarity.net (Mike Schinkel) > On May 15, 2021, at 4:20 AM, Rowan Tommins = wrote: >=20 > On 15 May 2021 00:09:41 BST, Paul Crovella = wrote: >> I think this highlights where the misunderstanding of this feature = is. >=20 >=20 > I think the fact that there is so much confusion highlights why it is = worth considering different designs. Exactly this. I have been debating whether to comment on this thread, but seeing = Rowen's comments mean I am not alone in my opinion so here goes. I too have been bothered with the inconsistent usage of the single = question mark ('?'). While it makes perfect sense once it is explained, = it is possibly not intuitive for those who have learned how to use a = command line shell where a single question mark indicates a single = "thing" (where "thing" is a single character in the shell.) =20 Using it in PHP to mean "one, or more" seems like it would cause = needless confusion given that intuition derived from command line = experience might lead developers to be confused. Better to use = something which would not be likely to lead developers astray I would = think. >=20 >> Partial application is about binding arguments. ? isn't an argument, >> it's an argument placeholder. It does two things: signals to create a >> closure wrapping the function rather than calling it immediately, and >> holds a position in the argument list so that an argument further to >> the right can be fixed (bound) at that time. >=20 >=20 > This is not a correct description of the current syntax. Currently, = "?" represents a *required* argument in the argument list, but *only* if = there is a fixed value to its right. If it appears at the end of the = argument list, or with only other ? tokens to its right, it *only* = signals that a partial should be created, and doesn't create a required = argument, even though it looks the same. >=20 > foo(?, 42) creates a closure with one required argument; foo(42, ?) = creates a closure with no required arguments >=20 >> Requiring additional trailing argument placeholders or adding an >> additional token `...?` unnecessarily complicates things, burdens the >> user, and only serves to further promote misunderstanding. >=20 >=20 > On the contrary, saying that "?" always means exactly one argument = massively simplifies the description of the feature. Why persist with a = version of the syntax that is so easy to misunderstand when we have a = really simple fix available? >=20 > I acknowledge the need for a syntax to say "accept zero or more = further arguments", but this doesn't need to overload the syntax for = "create a required argument here". >=20 > If the suggestion of ...? is too long, we could look at other options = like ... or ?? The syntax for "just make a closure and pass all = arguments through" would then be "foo(...)" or "foo(??)". Yes! =20 Since we need a sigil to indicate a function be wrapped in a closure I = was actually planning to propose `??` so I was pleasantly surprised to = see Rowan's suggestion. Ellipses would work too, but as I think `??` = would be easier to see in dense code, so I would prefer them. Which gives us:: function foo($a,$b,$c) {} $x =3D foo(??); // Wrap foo() in a closure which = expects 3 parameters $x =3D foo(?, 24); // Wrap foo() in a closure which = expects 2 parameters with `24` binding to `$b` $x =3D foo(?, 24, ??); // Same as foo(?, 24); > There is a *separate* question of whether arguments that weren't = *required* are passed along anyway. I'm less sure there's a right answer = there, and would be happy with a version where foo(?, 42) and foo(?, 42, = ...) were equivalent - that is, the trailing "all other arguments" token = would only be needed if there wasn't already a placeholder. Ditto, but with `??` preferred. Said another way, I am arguing exactly what Rowan arged except that I = have a preference for one sigil over the other. >=20 -Mike