4 ms·
To answer in reverse order: it doesn't need a gensym because it isn't introducing a new variable. The only variable being used is `dir`, and that is passed in.
by tmtvl 2y ago
To answer in reverse order: it doesn't need a gensym because it isn't introducing a new variable. The only variable being used is `dir`, and that is passed in.
As for why it's a macro rather than a function, I don't know, but it's possible that one of the features (probably variable substitution) is important.
(frobnicate (mcd (foo bar)))
Gets expanded to:
(frobnicate (fg
(mkdir -p (foo bar))
(cd (foo bar))))
At compile-time. I personally would have used a function declared inline, though.
- wk_end 2y agoBut my intuition is that it needs to (well, should) introduce a new variable in order to store the evaluation of dir, otherwise it gets evaluated twice. If (foo bar) has no side-effects, that’s just a performance loss, but if it does it’s probably behaving in unexpected ways.
- tmtvl 2y agoYeah, that is the strange thing, but binding it to a gensymmed variable would make it interchangeable with an inline function. That said, maybe `fg` is a macro which does some rewriting of its body, that could explain the decision.