Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_ as lambda shorthand #1177

Open
felixroos opened this issue Sep 3, 2024 · 0 comments
Open

_ as lambda shorthand #1177

felixroos opened this issue Sep 3, 2024 · 0 comments
Labels
feature completely new feature

Comments

@felixroos
Copy link
Collaborator

being able to write s("bd").sometimes(_.hurry(2)) instead of s("bd").sometimes(x=>x.hurry(2)) would be much simpler..
Right now, function arguments are a bit confusing, because sometimes you can use curried functions, e.g. fast(2) and in other cases, you cannot, e.g. x=>x.speed(2) . In cases where you can use curried functions, you still cannot chain on them: fast(2).hurry(2) does not work. Arrow functions work all the time but they are a bit verbose, so _. could be a good way to standardize function arguments. I chose "_" because it is one of the few special characters allowed as variable names + it looks like a placeholder which can be thought of the spot where the pattern on the left is inserted. The implementation could be done in various ways:

using transpilation / code as data:

  • very simple: code.replaceAll('_.', 'x=>x.') in the transpiler. potentially error prone in some minor cases, e.g. s("bd").sometimes(_=>_.hurry(2)) would become s("bd").sometimes(_=>x=>x.hurry(2)) . essentially it would mean you're only allowed to use _. as intended.
  • medium simple: doing the replacement on the AST, only if its a direct child of a function call?

using js

js is the safest bet, but it generates a bit more garbage (function is called 20 times per second and generates arrays all the time)

@felixroos felixroos added the feature completely new feature label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature completely new feature
Projects
None yet
Development

No branches or pull requests

1 participant