> On May 14, 2021, at 6:09 PM, Paul Crovella <paul.crovella@gmail.com> wrote:
>
> On Fri, May 14, 2021 at 2:49 PM Aaron Piotrowski <aaron@trowski.com> wrote:
>>
>> Consider function foo(int $x, int $y, int $z) {} with a partial defined as
>> $partial = foo(?, 42).
>>
>> If the partial is called as $partial(73, 8), should 8 be forwarded to
>> $z or should the call error as providing too few arguments?
>
> The 8 passes along to $z. There is no error, all required arguments
> have been provided.
In the current proposal, yes. In a hypothetical implementation where ? represented a single
argument, I was asking what made sense. In that situation, I think 8 passing along still makes
sense.
>
>> Or perhaps should the partial declaration should error, as it should have been foo(?,
>> 42, ?) or `foo(?, 42, ...?) so the partial provided all required arguments to foo.
>
> I think this highlights where the misunderstanding of this feature is.
> 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. Arguments are bound;
> argument placeholders are not, they exist only for convenience. The
> syntax foo(?, 42) doesn't call foo, let alone provide any arguments
> to it, it simply creates a closure that'll pass along 42 at the
> appropriate argument position along with whatever else it's provided
> with.
>
> Requiring additional trailing argument placeholders or adding an
> additional token ...? unnecessarily complicates things, burdens the
> user, and only serves to further promote misunderstanding.
>
My issue is the dual-meaning of ? in the current proposal. In foo(?, 42), the ?
represents a single argument, but adding a trailing ? (such as in foo(?, 42, ?))
represents any number of arguments. Would it perhaps make sense to make superfluous ? markers an
error?
foo(?); // Fine, needed to define a partial with no bound args.
foo(?, 42); // Ok, binds second arg.
foo(?, ?, 42); // Ok, binds third arg.
foo(?, 42, ?); // Error, unnecessary placeholder.
foo(?, ?); // Error, unnecessary placeholder.
The intention here is to keep the syntax unambiguous.
foo(?) == foo(?, ?) == foo(?, ?, ?) and so forth is not going to be obvious to everyone, so why
allow meaningless and misleading syntax.
Cheers,
Aaron Piotrowski