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

Pipe no longer clobbers _, fixes #181 #182

Closed
wants to merge 2 commits into from

Conversation

qqueue
Copy link

@qqueue qqueue commented Oct 18, 2012

...Is the end goal here, but I have questions on the approach, if you're willing to help.

The relevant code appears to be:

grammar.co:

    o 'Expression |> Expression' -> Block $1 .pipe $3

ast.co:

  pipe: -> @lines.push Assign(Var \_; @lines.pop!), it; this

I also found scope#temporary for getting a new name, but I'm unsure how to change the _ variable within the right-hand side of the pipe to the temporary binding. Is the implementation of pipe as just the Node#pipe method sufficient to do this, or would it be better to make Pipe extends Node to hold the logic for this?

Node#pipe is factored to as separate class Pipe.

The pipee `_` in coco is compiled to `_$`, using `o.scope.temporary \_`.
@qqueue
Copy link
Author

qqueue commented Oct 18, 2012

Went ahead and implemented a fix in 01bc54c, using scope#temporary \_, which usually generates _$ as the compiled pipee. All tests passing.

Concerns:

  • To allow the use of _ in coco while compiling to the pipee, I added a check in Var#compile, which may not be the best way to do this.
  • Is _$ obscure enough to not clobber variables? I can kind of see somebody else legitimately using _$, given they are the only two special characters you can use in identifiers. "underscore-money.js", perhaps.

@satyr
Copy link
Owner

satyr commented Oct 18, 2012

Viability aside, you're right that your proposal needs that kind of implementation.

I can kind of see somebody else legitimately using _$

Haven't seen that myself. Use of trailing $ in variable names is pretty rare, supporting #136.

@qqueue qqueue closed this Oct 22, 2012
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

Successfully merging this pull request may close these issues.

2 participants