satyr / coco

Unfancy CoffeeScript
http://satyr.github.com/coco/
MIT License
498 stars 48 forks source link

Allow `for` piping #201

Closed vendethiel closed 11 years ago

vendethiel commented 11 years ago

Basically just this :

for a
 1
|> c

(maybe allowing this ? =>)

for a in b
 1
.c
satyr commented 11 years ago

The former works on master.

As for the latter, that would mean allowing every possible construction to be dot-accessible. We might invoke some more ambiguities in some situations:

f ->
  a
.p
# `f(->).p` or `f((->).p)` ?
vendethiel commented 11 years ago

Not sure how that's an ambiguity since it has been a specialcase since coffee. I wasn't thinking about this behavior, but more imitating Ruby's end... one. Not sure that's as interesting as for piping tho.

if foo
 bar
else
 baz
.bat

being the same as

(do ->
 if foo
  bar
 else
  baz
)bat
satyr commented 11 years ago

This particular specialcase (. after block closing implicit call) has been justified because -> ... etc can't directly be dot-accessed.

Not sure that's as interesting as for piping tho.

It's technically possible but probably YAGNI.

vendethiel commented 11 years ago

Thought so. Having the former is enough for me, but some cases are interesting. I'd love to be able to do

bar =
 * \abc
 * \def
.join ' '
satyr commented 11 years ago

That's exactly the can of worms I'm afraid to open; it's not immediately clear what's going on.

Following your if examples, it would parse as:

(bar =
  \abc
  \def
).join ' '

but the intention is probably:

bar = [
  \abc
  \def
].join ' '
vendethiel commented 11 years ago

I understand your concerns, and I know you're right, as usual.

satyr commented 11 years ago

That said, it's certainly convenient to be able to:

bound = ->
  ...
.bind foo

zs = for x of xs
  ...
.concat ys

rather than:

bound = (->
  ...
)bind foo

zs = do
  for x of xs
    ...
.concat ys

It should be safe to make literal functions and "KEYWORD Expression? Block" constructions chainable.

vendethiel commented 11 years ago

For the second part, yes. For the first part, maybe I'd say no for consistency, as we saw before

satyr commented 11 years ago

Discluding function literals:

Lemme rephrase: make things that require Block chainable.

vendethiel commented 11 years ago

That's interesting. Does that mean dropping the OUTDENT DOT specialcase in addImplicitParentheses? 'Cause I think that's the most common use case.

satyr commented 11 years ago

Does that mean dropping the OUTDENT DOT specialcase

Nope. Being able to chain from implicit calls is far more important.