Partial application chose to limit the scope of `?` to argument positions in an
argument list for a number of reasons. The primary being this case (assuming
arbitrary expressions were allowed):
```js
let i = 0;
const g = f({ x: i++, y: ? });
```
The goal of partial application was to “fix” non-placeholder arguments at the
time the partial function result is bound. This means that `i++` above should
evaluate only once. However, if we allowed placeholders in arbitrary parts of
an expression, to preserve this behavior we would have to be able to “partially
fix” any arbitrary expression (such as the property names and property values
of the object literal above). Various committee members indicated that they
were very much opposed to this kind of partial fixing.
The other problem with placeholders is scoping. The above example could have
two interpretations: One where `g` is a partial function for `f` with an
argument that fills in the `y` property, and one where `f` is called with an
object that has a property `y` that is an identity function.
A placeholder as an arbitrary expression is also complicated by something like
`g(f(?))`. If `?` is an arbitrary expression, you need to syntactically mark
the boundary of the expression, otherwise a user could expect the result to be
either `x => g(f(x))` or `g(x => f(x))`. In Scala’s case, you end up needing to
use a block-style for these cases. If `?` is scoped to its immediate argument
list and does not allow arbitrary expressions, then there becomes only one
possible interpretation (in this case, `g(x => f(x))`). In this way, partial
application is like a more powerful syntactic variation of
Function.prototype.bind, as Function.prototype.bind always fixes arguments in
the function’s immediate argument list.
Ron
From: es-discuss <[email protected]> On Behalf Of Andrew Kaiser
Sent: Wednesday, November 28, 2018 11:57 AM
To: [email protected]
Cc: [email protected]
Subject: Re: New Proposal: Placeholder syntax
This proposal also works with simple math operations and for accessing fields
on objects. The partial application lists these expressions as invalid.
```js
// invalid
f(x + ?) // `?` not in top-level Arguments of call
x + ? // `?` not in top-level Arguments of call
?.f() // `?` not in top-level Arguments of call
```
Admittedly they chose not to include these operations because of the complexity
it would add to the transpilation, but the placeholder proposal is simpler in
nature. The partial application proposal alters what is returned by a function
call, the placeholder proposal replaces an argument inline, and the value a
called function returns does not change.
On Wed, Nov 28, 2018 at 2:35 PM Jordan Harband
<[email protected]<mailto:[email protected]>> wrote:
It seems like the partial application proposal covers all of the use cases of
yours, at a first glance. What does yours offer that partial application does
not?
On Wed, Nov 28, 2018 at 11:23 AM Andrew Kaiser
<[email protected]<mailto:[email protected]>> wrote:
Do you see a way these proposals can work together? I believe they are solving
different needs. Both proposals produce a new anonymous function, but partial
application deals with currying, while the placeholder proposal tries to
prevent writing a function at all. I can actually see the two working together:
```js
const filenames = ['file1.txt', 'file2.txt' 'output.log' ]
const fileContainsContent = (filename, content) =>
fs.readFileSync(filename).toString().includes(content)
const fileSearchers = filenames.map(fileContainsContent(*, ?))
const filesContainingSearch = fileSearchers.filter(searcher =>
searcher('foobar'))
```
This isn't a very useful example, but you can see how the proposals differ
accomplish different things
On Wed, Nov 28, 2018 at 1:30 PM Jordan Harband
<[email protected]<mailto:[email protected]>> wrote:
You may be interested in the partial application proposal:
https://github.com/tc39/proposal-partial-application<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftc39%2Fproposal-partial-application&data=02%7C01%7Cron.buckton%40microsoft.com%7C3f77a64eda334aa76bd708d6556ba4d0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636790318211957611&sdata=Esl%2F8p6N7B8pJuXqyycMfmhIB38h67zrAwj9CzQLieU%3D&reserved=0>
On Wed, Nov 28, 2018 at 10:17 AM Andrew Kaiser
<[email protected]<mailto:[email protected]>> wrote:
Hi all,
I have created a short proposal to introduce syntactic sugar for anonymous
functions in a 'scala-like' manner, linked here
https://github.com/andykais/proposal-placeholder-syntax<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fandykais%2Fproposal-placeholder-syntax&data=02%7C01%7Cron.buckton%40microsoft.com%7C3f77a64eda334aa76bd708d6556ba4d0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636790318211967623&sdata=UPfh4NQUw38f03Qq92xZWVj2%2BEH3esAg6SXhHzXd51U%3D&reserved=0>.
I am hoping to hear feedback on whether or not this is interesting to people,
as well as feedback on the proposal itself (e.g. is there a better operator to
use than ` * `)
_______________________________________________
es-discuss mailing list
[email protected]<mailto:[email protected]>
https://mail.mozilla.org/listinfo/es-discuss<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&data=02%7C01%7Cron.buckton%40microsoft.com%7C3f77a64eda334aa76bd708d6556ba4d0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636790318211977632&sdata=g8ga9mOfb5UX8ZYRMlus%2BFnZDAcoGv7S%2FqlwXZ%2FU2HI%3D&reserved=0>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss