qi
qi copied to clipboard
Preserve threading direction in nested forms
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"
As noted in these meeting notes and in subsequent notes, using a syntax parameter is likely to be a good way to achieve this.