qi icon indicating copy to clipboard operation
qi copied to clipboard

Preserve threading direction in nested forms

Open countvajhula opened this issue 3 years ago • 1 comments

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 avatar May 11 '21 18:05 countvajhula

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

countvajhula avatar Jan 30 '24 04:01 countvajhula