I’ll try to explain crudely what I understand of wikitext rendering, but there will be approximations and imprecision, please bear with me
As far as I can tell, your initial code isn’t working because macros are just “text snippets” with a name, they are not “computed” ( = rendered) until after they are used.
When a tiddler is displayed, during the first pass of the rendering process, macro calls are replaced with their definition (ie. the <<macro name>> is replaced by the macro’s content), and in a later pass the widgets (like <$list>) are rendered (ie. replaced by html + css).
In your code, when the macro is called in the filter, during the first pass the content of the macro definition is inserted into the filter, just like if you’d written this:
which doesn’t work because it’s not a valid filter syntax.
In order to solve this problem, you can use a function instead of a macro, because a function is a “custom filter”, which TW’s rendering process recognizes and treats as such.
There are other options, like using a variable initialized with the result of a “filtered transclusion” like this:
It’ll be another 75 years before the code offered by @tw-FRed actually creates trouble (unless you’re working already with historical dates!), but suppose you were to add a Tag (Day) field… Month and Day values may often be the same, and the function expression, if lacking the = prefixes, will remove duplicate values, so February 2 would give you just 02, not 0202.
(Technically, you just need the = before values after the first one. But whenever I want to preserve values despite duplication, I add the = to each, so that it’s easy to move things around, and there’s a clear visual indicator that this value should not be subject to de-duplication.)