Giter Club home page Giter Club logo

Comments (13)

haltcase avatar haltcase commented on June 6, 2024

This would be nice - just need to figure out the syntax. Thanks for opening.

from babel-plugin-partial-application.

haltcase avatar haltcase commented on June 6, 2024

I have a few ideas - I hope I can get a lot of feedback on these. Since we have to stick to legal JS syntax we're limited to a few similar constructs.

ideas

Desired output

const isNaN = (_a) => {
  return _a !== _a;
};

Syntax options

// function call-esque
const isNaN = _(1) !== _(1)
// tagged template literal
const isNaN = _`1` !== _`1`
// this one would require inheriting from function bind syntax
// which is an early stage proposal and isn't guaranteed to stick around
const isNaN = _::1 !== _::1

... others?

thoughts

Of all the above so far, _(1) probably makes the most immediate sense. I actually like the way that the tagged template looks though ( _`1` ). Function bind :: just isn't a very safe pick yet, or it would be a neater choice.

Suggestions? Thoughts? Explosive ideas? 🙏

from babel-plugin-partial-application.

Nitive avatar Nitive commented on June 6, 2024

Maybe just _1, without brackets or quotes?
And what do you think how should be interpreted using few _ (without argument number)?
Few arguments like it implemented now (_ !== _ => (x, y) => x !== y)? Or one argument like in Clojure (_ !== _ => x => x !== x)?

from babel-plugin-partial-application.

haltcase avatar haltcase commented on June 6, 2024

Maybe just _1, without brackets or quotes?

I'd rather not increase the number of identifiers we're 'reserving'.

And what do you think how should be interpreted using few _ (without argument number)?
Few arguments like it implemented now (_ !== _ => (x, y) => x !== y)? Or one argument like in Clojure (_ !== _ => x => x !== x)?

I think that both ways are technically valid. Clojure interprets them as the same argument. Scala expands them to two separate arguments. Kotlin's it is only for a single argument so I guess that's more in line with Clojure.

I like the multiple argument way better, since _ + _ would define a function adding two numbrers ( or concat'ing two strings ), and that makes more sense to me than adding something to itself.

from babel-plugin-partial-application.

wcjohnson avatar wcjohnson commented on June 6, 2024

Seems like a good time to add swizzle: f(_2,_1) => (_2, _1) => f(_1, _2)

from babel-plugin-partial-application.

haltcase avatar haltcase commented on June 6, 2024

@wcjohnson I fought it but it's back to bite :) swizzle would go right along with this.

from babel-plugin-partial-application.

haltcase avatar haltcase commented on June 6, 2024

I've got a rough initial shot at this in a feature branch. Would appreciate anyone interested giving it a go, and I'll let it kick around for a bit. For now I've gone with the _`1` syntax which I do like, but if that turns out to be a bust it shouldn't be too awful to change.

You can see a couple examples in the initial test files here.

from babel-plugin-partial-application.

haltcase avatar haltcase commented on June 6, 2024

I've rebased & updated the positional-placeholders branch to the current master and improved the implementation. It's available on npm as [email protected] .

While the playground won't be updated with it until it hits master, @wcjohnson was cool enough to add it to his lscdiag tool - where you can use it along with the LightScript language if you want ( I highly recommend it 😉 ).

Here's a permalink to set you up on lscdiag with the plugin.

@wcjohnson 1.6.0-alpha.2 takes care of the compilation differences you pointed out.

from babel-plugin-partial-application.

wcjohnson avatar wcjohnson commented on June 6, 2024

@citycide alpha.2 on lscdiag. Bug with a single placeholder making an invalid node still present. IMO, that should either be an error or an identity function (the latter may actually be useful occasionally)

https://wcjohnson.github.io/lscdiag/?v=1&s=eMKcw43CkU1uw4MgEEbCr1LDjSrClRzDhwQ3acK8w7IJesKBNsKywqcYOzQYKD9SGsOLdy_DlMObw5bDq8KyYRDCjzfDs8KJCXpxw7PDgXIHw5UEw43CiCbDrXU9csKPHXpMJ8O2QW9fwpTCnsKORVzDtHrCoMKlwrpfB3YnUHkbeMK2AMOlw7NQw4Z7wpIAw7pJNBnDu24Bw6ZsTTHCgcOTw4Eywp4qw6kYVMKww5s9VMKPb8KqaUnCu2nDmn0ba8KIwo4gEsOiw7E9wo7Dulpkw4U5A8OHJWfCnncvwrrCi8OvVcKQMsO1w5LCqhfDg8OPw6B6NEJyG8KdUgwXw6_CmBXDhsOXRcO-wpTCnyADI8ODIFTCssKBQcOrBcOKLRojBUMvwrTCqkl-w4jCiy1Kc8OBfA_Dp3leDcO6e8KMw40Sw6PCnwTCiG4pwpxPw7zDnx_CssKWMjrCvgEnw5DCssOE

from babel-plugin-partial-application.

haltcase avatar haltcase commented on June 6, 2024

I'm making both of these errors:

_`1`

const thing = _`1`

... since I think for an identity function there are more obvious ways. Any suggestions for decent error messages?

_`1`
// -> 'Positional placeholders must be part of some expression.'

const thing = _`1`
// -> 'Positional placeholders alone are not a valid RHS value.'

from babel-plugin-partial-application.

wcjohnson avatar wcjohnson commented on June 6, 2024

Those look reasonable to me. They could both be put under the umbrella of "Trivial partial application is not allowed" or something like that.

from babel-plugin-partial-application.

haltcase avatar haltcase commented on June 6, 2024

I published 1.6.0-alpha.3 with those changes. Might be final 1.6.0 also but I'm still waffling over the syntax.

from babel-plugin-partial-application.

haltcase avatar haltcase commented on June 6, 2024

To all interested parties - I'm straight up ruling out _1 as a possible syntax. I actually had it implemented locally and was considering pushing that before running into a major issue with it. Those 10 new identifiers ( _0 ... _9 ) would now be newly undefined in each and every file, which would be a huge pain for linters. Unless you define them as globals in editors, configs, etc.

So with that out of the way I'll be making this the master tomorrow ( probably ) and publishing 1.6.0 proper after that, as long as there's no further feedback.

from babel-plugin-partial-application.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.