News for hackers. Stuff that matters.
Re:Mount Unix system into Common Lisp image by wk_end on Saturday September 21, 2024 @11:02PM (#41614325)
My Lisp is rusty and was never that great to begin with, but:

Why is mcd a macro? And isn’t it missing a gensym?

Re:Mount Unix system into Common Lisp image by tmtvl on Sunday September 22, 2024 @12:49AM (#41614701)
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.
Re:Mount Unix system into Common Lisp image by wk_end on Sunday September 22, 2024 @01:20AM (#41614789)
But 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.
Re:Mount Unix system into Common Lisp image by tmtvl on Sunday September 22, 2024 @01:51AM (#41614877)
Yeah, 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.