Here's an example of some code from LaTeX's \DeclareFontFamily:
\def\reserved@a{#3}
\global
\expandafter\let\csname #1+#2\expandafter\endcsname
\ifx \reserved@a\@empty
\@empty
\else \reserved@a
\fi
I could be wrong, but to me this looks identical to:
\expandafter\gdef\csname#1+#2\endcsname{#3}
Now, the source for this code comments:
We compare
\reserved@awith\@emptyIf these two are the same we\letthe ‘extra’ macro equal to\@emptywhich is not the same a doing a\letto\reserved@a— the latter would blow one extra memory location rather then reusing the one from\@empty.
But if we're not re-using the contents of \reserved@a after this point (which we're not, as far as I can see), there's no reason to go this roundabout route, right?
\let? This is very interesting. – Martin Scharrer Feb 23 '11 at 09:37\letto each other have only one definition in memory (the hash table entries point to the same definition), whereas\defcreates independent definitions even if the two are identical. – Joseph Wright Feb 23 '11 at 10:06\def\a{}\def\b{}takes more (or twice as much) memory as\def\a{}\let\b\a. (I still think\reserved@aisn't reused.) Hence my first suggestion wouldn't be a good idea (back then when memory was scarce). WDYT? More importantly, does it matter these days? – Will Robertson Feb 23 '11 at 13:33\reserved@aisn't the key here, it's the\@emptybranch that does the saving. I'd say today it doesn't matter at all: one of the problems with the current kernel is that these tricks make maintenance much harder. – Joseph Wright Feb 23 '11 at 13:37\reserved@aused in e.g. environments, and everywhere in LaTeX? – Bruno Le Floch Feb 23 '11 at 13:41\reserved@a(and@b, etc.) are scratch registers used in the kernel and assumed not to interact with any other code (unlike\@tempaand so on). – Will Robertson Feb 23 '11 at 14:02\cs_set_eq_probably_empty:NNthat incorporates this test but I really don't think it's worth it.) – Will Robertson Feb 23 '11 at 14:05I still think \reserved@a isn't reused: it is reused all over the place, so you're not wasting any memory cell, since that definition would be cleared whenever\reserved@ais redefined. – Bruno Le Floch Feb 23 '11 at 14:38\reserved@a’ aren't reused. Hence why save the argument to a macro in the first place? But Joseph answered that question now. Thanks:)– Will Robertson Feb 23 '11 at 14:43