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

Ambiguity from nested anonymous functions #233

Open
Merlin04 opened this issue Oct 9, 2021 · 3 comments
Open

Ambiguity from nested anonymous functions #233

Merlin04 opened this issue Oct 9, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@Merlin04
Copy link

Merlin04 commented Oct 9, 2021

Is your feature request related to a problem? Please describe.
I came across Clio and it looks really cool, I'm excited to try using it for some projects! One issue I ran into is that in nested anonymous functions I can't figure out how to specify which parameters belong to which function.

For example, here's a function in JavaScript:

const thing = (m) => [...Array(5).keys()].map(item => item * m).forEach(item => console.log(item));

I'm not sure how I'd write this in Clio due to the nested anonymous functions creating ambiguity (I can't specify that item is a parameter of the inner function and m is a parameter of the outer function):

thing = (0..5 -> .toArray -> * (@item * @m) -> console.log)

Describe the solution you'd like
I'm not sure how this could be resolved while keeping Clio's implicit parameter syntax. Maybe there could be some sort of new syntax like JavaScript's function() {} that keeps the fn and explicit arguments but still returns an anonymous function? Something like:

thing = fn m: (0..5 -> .toArray -> * (@item * m) -> console.log)

Describe alternatives you've considered
I could just write thing as a regular function:

fn thing m:
  0..5 -> .toArray -> * (@item * m) -> console.log

But this doesn't return an anonymous function so it wouldn't be a valid workaround in all cases.

@Merlin04 Merlin04 added the enhancement New feature or request label Oct 9, 2021
@Merlin04 Merlin04 changed the title Ambiguity from ested anonymous functions Ambiguity from nested anonymous functions Oct 9, 2021
@pouya-eghbali
Copy link
Member

The anonymous functions need some work, I'll address this issue in the next release. The implicit anonymous functions are useful in cases like

arr -> .filter (@it % 2)

so I'd like to try and keep that syntax, but yes, your argument is valid and the issue should be resolved.

@pouya-eghbali
Copy link
Member

Personally, I'm not a fan of long anonymous functions, looking at a function it should be obvious what the function does.

A good read on this topic can be found here: https://hackernoon.com/three-reasons-i-avoid-anonymous-js-functions-like-the-plague-7f985c27a006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants