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

Preserve threading direction in nested forms #5

Open
countvajhula opened this issue May 11, 2021 · 1 comment
Open

Preserve threading direction in nested forms #5

countvajhula opened this issue May 11, 2021 · 1 comment

Comments

@countvajhula
Copy link
Collaborator

countvajhula commented May 11, 2021

Arguments are by default supplied in the leading positions. Employing the right-threading operator causes arguments to be supplied in the tail position, but this doesn't propagate to nested forms, requiring a fresh use of right-threading within those nested forms.

Example:

(on ("b") (~>> (string-append "a"))) ; => "ab"

as expected, but

(on ("b" "c") (~>> (>< (string-append "a")))) ; => "ba", "ca"

rather than the expected "ab", "ac"

Implementation Considerations:

At the moment, right-threading is implemented by setting a syntax property on the contained clauses in (~>> clause ...). This happens only in the expansion rule for the right-threading operator, and as a result, any nested clauses don't inherit this property since other expansion rules aren't aware of it.

Replacing all of the rewrite rules to explicitly propagate syntax properties via datum->syntax instead of a simple #' would possibly work, but it seems gratuitous. Maybe there's an easier way.

Workaround:

Explicitly indicate right-threading within the nested form:

(on ("b" "c") (~>> (>< (~>> (string-append "a"))))) ; => "ab", "ac"

or use a template:

(on ("b" "c") (~>> (>< (string-append "a" _)))) ; => "ab", "ac"
@countvajhula
Copy link
Collaborator Author

As noted in these meeting notes and in subsequent notes, using a syntax parameter is likely to be a good way to achieve this.

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

1 participant