Template metafunctions lack `syntax-local-template-metafunction-introduce`
Nobody has claimed this yet.
- Dominant language
- Racket
- Stars
- 5.2k
- Forks
- 698
- Avg merge
- 18h 34m
- Merged PRs (30d)
- 5
Description
Template metafunctions flip the syntax-local-introduce scope on their input and on the metafunction's result, and also flip their own mark. Nested calls to template metafunctions instead flip the old mark and flip their own new, fresh mark.
Unfortunately, the current implementation does not provide a syntax-local-introduce-like mechanism like syntax-local-match-introduce or syntax-local-require-introduce.
Below is a use case justifying the need for syntax-local-template-metafunction-introduce. I strongly suspect that a syntax-local-match-introduce would also solve issue #1493 .
The goal is to implement a metafunction which “caches” the syntax for the expressions it generates, so that:
(with-cache
(template (+ (cache expression1)
(cache expression1)
(cache expression2)))
is equivalent to:
#'(let ()
(define c1 expression1)
(define c2 expression2)
(+ c1 c1 c2))
Normally, one would use syntax-local-lift-expression to implement this kind of behaviour, but in my case I am interested in “caching” TR type definitions, which are bound as syntax, and therefore cannot be lifted with syntax-local-lift-expression. A simple and easy solution is to implement this via a cache-type template metafunction, unfortunately the extra scopes mean that uses of c1, c2 etc. don't "see" the corresponding definition.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing syntax-local-match-introduce and syntax-local-require-introduce mechanisms, then compare them with the scope handling for template metafunctions described here. The change is complete when a syntax-local-template-metafunction-introduce mechanism supports the cache example so generated identifiers such as c1 and c2 resolve to their corresponding definitions.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100