# How can I improve my knitting?

**URL:** <https://racket.discourse.group/t/how-can-i-improve-my-knitting/3239>\
**Category:** Questions & Answers\
**Created:** [October 18, 2024, 1:30pm UTC](https://racket.discourse.group/t/how-can-i-improve-my-knitting/3239 "2024-10-18T13:30:29Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![lexi.lambda](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/lexi.lambda/32/1969_2.png) [@lexi.lambda](https://racket.discourse.group/u/lexi.lambda)\
**Post date:** [October 19, 2024, 9:53am UTC](https://racket.discourse.group/t/how-can-i-improve-my-knitting/3239/5 "2024-10-19T09:53:10Z")

</div>

It is worth thinking about the fact that `~>` is a very unusual macro, because it is quite explicitly about pushing (“threading”) forms inside other forms. When you write

```scheme
(~> foo
    (bar baz))

```

then the expansion is `(bar foo baz)`, and the idea is this is just that second `~>` subform with `foo` slipped into the middle.

Most macros do not do this, and almost none do it so mindlessly. In fact, I would even argue that most macros _should not_ do this. Macros should be syntactic _abstractions_, and their users should not need to reason about them in terms of what they expand into. If that is the case, it makes sense for syntax introduced by the macro to be attributed to the macro: the macro “takes responsibility” for whatever it expands into.

What makes `~>` so useful is also what makes it so unusual: it’s really just a syntactic abbreviation, and it exists purely to rearrange syntax objects. `~>` neither knows nor cares about what its subforms actually mean. For this reason, the user of `~>` really does want to think of the above example as _precisely equivalent_ to if they had written `(bar foo baz)` directly, in the original source file, and `~>` should therefore take care to honor that expectation.

> [@bakgatviooldoos](#):
>
> Edit: as a real example from the code, I have
> 
> > (my-macro ex (yn ...)) -\> (apply yn ... (knits ex list))

Here, you are introducing a use of `apply` in the expansion, and you are almost certainly expecting `(apply ....)` to mean “a procedure application”. This means that you are in fact _depending_ on the binding of `#%app` being the one from `racket/base`, as your expansion would fail to work correctly if `(#%app apply ....)` meant something else. This is really just an illustration of why macro hygiene is so important: you want your expansion to mean what it means in the module where you defined `my-macro`, not what it would have meant in some entirely different module with some other binding for `#%app`.

I don’t think I can say terribly much more without understanding what `my-macro` in your example is actually intended to do, but at the very least, the lexical context of the outermost syntax list (i.e. the context “on the parentheses”) should come from the template, not the input to the macro.

---

_[View the full topic](https://racket.discourse.group/t/how-can-i-improve-my-knitting/3239)._
