News for hackers. Stuff that matters.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by wwwigham on Wednesday January 31, 2018 @02:23AM (#16272166)
If you really like the idea of syntactic partial application in your JavaScript, you should check out the stage 1 tc39 proposal for exactly that: https://github.com/rbuckton/proposal-partial-application It's slowly being worked through the committee, so if you care enough about the feature, you should consider voicing your support.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by citycide on Wednesday January 31, 2018 @11:57AM (#16275297)
I agree! It's not as powerful as this macro but I really want this in the standard.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by a-saleh on Wednesday January 31, 2018 @02:56AM (#16272263)
Funny, I already kinda use partial application in Javascript, just by using curried functions a lot. I.e.

const add = x => y => x + y

This is definitely non-idiomatic, but the definition syntax itself doesn't look that bad, if you can stomach writing add(1)(2) to use it.

I do agree that using _ would probably be a better solution :-)

Re:Partial Application and Lambda Parameter Syntax for JavaS... by citycide on Wednesday January 31, 2018 @11:47AM (#16275215)
Right, this is currying not partial application. And it comes with the drawback that you always have to call the function multiple times. You can't provide all the parameters in one list, which rules out things like spread arguments. That's not the case with `param.macro`, depending on how you apply of course.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by Traubenfuchs on Wednesday January 31, 2018 @03:24AM (#16272365)
Am I missing something? Why not just

const add = (a,b)=>a+b?

Re:Partial Application and Lambda Parameter Syntax for JavaS... by a-saleh on Wednesday January 31, 2018 @05:09AM (#16272794)
Well usually it would be for something that is useful, like

const greaterThan = x => y => y > x

and then I can do thins like

numbers.filter(greaterThan(10))

because greatherThan(10) is a function (and I hope I did put the correct comparison operator :)

Re:Partial Application and Lambda Parameter Syntax for JavaS... by masklinn on Wednesday January 31, 2018 @05:20AM (#16272842)
It also works better on languages using free functions than those using method calls e.g. in Haskell you have

    filter :: (a -> Bool) -> [a] -> [a]
so you partially apply to a predicate to get a specific filter condition which you can apply to various contexts e.g.

    over10 = filter (>= 10)
That's why functional languages tend to put the callback first in HoFs, it's usually the more common partial application case.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by ponkin on Wednesday January 31, 2018 @03:53AM (#16272481)
You can not use partial application with that. for example const add = x=>y=>x+y

can be partialy applied like the following const add3 = add(3) // this is also a function

Re:Partial Application and Lambda Parameter Syntax for JavaS... by masklinn on Wednesday January 31, 2018 @05:22AM (#16272853)
> You can not use partial application with that.

You can:

    const add3 = add.bind(null, 3)
Re:Partial Application and Lambda Parameter Syntax for JavaS... by a-saleh on Wednesday January 31, 2018 @11:27AM (#16275051)
I still like currying better, but I just might be weird like that :-)
Re:Partial Application and Lambda Parameter Syntax for JavaS... by masklinn on Wednesday January 31, 2018 @11:36AM (#16275122)
I only asserted that you could partially apply regular functions. But I don't think currying looks or feels nice in Javascript.

Proper curried languages are definitely better suited for partial application though.

Re:Partial Application and Lambda Parameter Syntax for JavaS... by mwilliaams on Wednesday January 31, 2018 @02:16PM (#16276654)
You could use default parameters in this case.

const add = (a, b=0) => {return a+b}

Re:Partial Application and Lambda Parameter Syntax for JavaS... by rmrfrmrf on Wednesday January 31, 2018 @07:57AM (#16273461)
> In Kotlin specifically, this is a shorthand for anonymous functions where, if you don’t specify an argument, one will automatically exist with the name it

I'm pretty sure Kotlin borrowed this idea from Groovy.

Re:Partial Application and Lambda Parameter Syntax for JavaS... by citycide on Wednesday January 31, 2018 @11:49AM (#16275225)
I'm pretty sure that's correct but Kotlin is a more recent reference so I chose it instead.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by citycide on Wednesday January 31, 2018 @11:44AM (#16275186)
Hi everyone, I'm the author. Looks like I'm a little late to the party (this post snuck by me) but I'll try to answer any questions you might have.

I'd also like to point out the online playground [0] which allows you to use this directly in your browser and see what it compiles to.

[0]: https://citycide.github.io/param.macro

Re:Partial Application and Lambda Parameter Syntax for JavaS... by some1else on Wednesday January 31, 2018 @07:00AM (#16273199)
Nice article. I still prefer arrow functions over positional arguments though, because this approach trades some clarity for syntactic sugar. Until partial application becomes part of JavaScript, the import statement will probably outweigh the informative "boilerplate" it helps obscure anyway (there's rarely more than one use case for partial application inside a well-factored component).
Re:Partial Application and Lambda Parameter Syntax for JavaS... by kalekold on Wednesday January 31, 2018 @08:22AM (#16273596)
Partial application is a technique, not a language construct. Plus, you can already use partial application in JavaScript and have been able to for years.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by optimuspaul on Wednesday January 31, 2018 @09:48AM (#16274205)
Doesn't javascript have enough magic in it to make code difficult to follow? What is the benefit to adding more?
Re:Partial Application and Lambda Parameter Syntax for JavaS... by citycide on Wednesday January 31, 2018 @11:56AM (#16275280)
I think the fact that this (and all macros with `babel-plugin-macros`) requires an explicit import helps keep it out of magic territory. You do have to become aware that the symbols transform the function/argument they're a part of, but this is only really new to JS devs. It's familiar in a bunch of other languages.

I documented how they work in this part[0] of the readme.

[0]: https://github.com/citycide/param.macro#differences-between-...

Re:Partial Application and Lambda Parameter Syntax for JavaS... by skybrian on Wednesday January 31, 2018 @02:00PM (#16276488)
The import tells you that some of the expressions in a file might be functions, but not which ones. For each definition, you have to read the entire expression to tell whether it's a function or evaluated immediately, and what its arity is. No thanks! Reading the entire file just to find out its API is no fun.

I like the direction typescript is going, where you can easily see not only the arity but the type of each parameter, without reading the function body. This is more skimmable.

Re:Partial Application and Lambda Parameter Syntax for JavaS... by carapace on Wednesday January 31, 2018 @12:07PM (#16275378)
I upvoted you because I want an honest answer from somebody.

It's like if mountain-climbing caused more mountains to rise up above you. This is great if you love climbing mountains but terrible if you actually want to reach the top.

We keep "improving" our languages but very few of us take the time to measure our real productivity.

What is the business value case for not using Elm-lang?

At some point, if we are "doing it right" the total amount of code in the world (modulus copies) should be contracting.

Re:Partial Application and Lambda Parameter Syntax for JavaS... by kalekold on Wednesday January 31, 2018 @08:25AM (#16273610)
Are babel plugins the new C preprocessor? and have all the problems associated with that.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by nsenifty on Wednesday January 31, 2018 @10:26AM (#16274532)
babel-plugin-macros allow hygienic macros (https://en.wikipedia.org/wiki/Hygienic_macro) so they don't have the problems associated with C macros.
Re:Partial Application and Lambda Parameter Syntax for JavaS... by abritinthebay on Wednesday January 31, 2018 @01:06PM (#16275960)
Not specifically, no. But they can be abused in similar ways.