Hi, Racket Discourse.
I have been messing around with the following little syntax, called knitting, which is basically a thin wrapper around @lexi.lambda's threading, which she recently updated.
The excitement got me thinking about theading values, which can become yucky to deal with. So why not build on the shoulders of giants.
My question is, how can I improve the macro-side of things? I have been reading through the older version of the source for threading and see for example that @lexi.lambda uses adjust-outer-context with the remark
; Adjusts the lexical context of the outermost piece of a syntax object;
; i.e. changes the context of a syntax pair but not its contents.
(define-for-syntax (adjust-outer-context ctx stx [srcloc #f])
(datum->syntax ctx (syntax-e stx) srcloc))
Why is this necessary, or, a good thing? What other bits of smelly code are lurking in my definitions?
First, the definitions:
Edit: public gist of the definitions.
The basic idea is that we stitch together yarns. A yarn is any expression that isn't a "knitting phrase", such as %, #:knit, &, or #:purl. A "knit" is executed regardless, and a "purl" is executed conditionally.
The same idea applies as with threading, but we may enjoy greater pre-emption and control.
Re: the adjust-outer-context: I just ran into a bug caused by carelessly renaming things in the macro definitions, leading to a weird error (because it goes back to the macro source!).
But, after adjusting the context, it seems to yield a more intelligible result. Probably not the only reason to do that, but it is interesting.