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

[Feature request] Add . (dot) or other symbol(s) as variable reference in assignment block #180

Closed
demark opened this issue Oct 17, 2012 · 5 comments

Comments

@demark
Copy link

demark commented Oct 17, 2012

Currently we have this sugar: some.long.long.long.variable .= to-upper-case!

But we often have a lot of functions from some libs that takes var as argument and returns new value.

I suggest to add . (dot) as variable reference in the assignment block:

some.long.long.long.variable = '<b>hello</b> world!'

some-external-lib.sanitize = (s) -> s.replace /<\/?[^>]+>/g, ''

some.long.long.long.variable =  some-external-lib.sanitize .
                                .replace /\s+/g, '_'
                                .to-upper-case!

And we can use some.long.long.long.variable = . .to-upper-case!

Maybe instead of dot use &. or $& (like in regex)

I think this will be very usable.

@satyr
Copy link
Owner

satyr commented Oct 17, 2012

I've considered this feature, but been dismissing it due to:

  • difficulty wrt destructuring, e.g.: [a, b] = f(.).
  • the overhead (extra traversing of RHS on each assignment) it would add.

@demark demark closed this as completed Oct 17, 2012
@demark demark reopened this Oct 17, 2012
@demark
Copy link
Author

demark commented Oct 17, 2012

So, what if strict assignment with reference only to ordinary variables (e.g. a = ..., b = ...)
Second, afaik this overhead will only cause on preprocess. In js-output there only need to replace reference symbols. Am i right?

@satyr
Copy link
Owner

satyr commented Oct 17, 2012

only to ordinary variables

Yup, we'd have to disallow it on destructuring LHS.

this overhead will only cause on preprocess

Right.

@satyr
Copy link
Owner

satyr commented Jan 11, 2013

Whipped up a trial impl there. Some notes:

  • Simbol is <>. Standalone . as proposed is too iffy.
  • Does not cross-scope. E.g. f = -> <> is syntax error.
  • Turns out destructuring is naturally prohibited because RHS is evaluated first and gets stray error.

@satyr
Copy link
Owner

satyr commented Feb 11, 2013

Merged as is.

@satyr satyr closed this as completed Feb 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants