ideas.tex (1908B)
1 \def\ifisempty#1\then{\if\relax\detokenize{#1}\relax \else \ea\unless \fi \iftrue} 2 \let\then=\iftrue 3 4 % \long\def\macargsundelim#1{\@macargs\@macargsundelim#1\@macargs} 5 % \long\def\macargsbrace#1{\@macargs\@macargsbrace#1\@macargs} 6 % \long\def\@macargs#1#2{% Excercise for the reader: understand this. 7 % \ifx\@macargs#2\else 8 % \ifcat##\noexpand#2\else 9 % \ea\ea\ea\@macargs 10 % \fi 11 % \ea#1% 12 % \fi 13 % } 14 % \def\@macargsundelim#1{#########1\@macargs\@macargsundelim} 15 % \def\@macargsbrace#1{{###1}\@macargs\@macargsbrace} 16 17 18 %%% Namespaces 19 20 % Primitives that define control sequences. (I may be missing some.) 21 \chardef 22 \mathchardef 23 24 \countdef 25 \dimendef 26 \muskipdef 27 \skipdef 28 \toksdef 29 \attrdef 30 31 \def 32 \edef 33 \gdef 34 \xdef 35 36 \let 37 \glet 38 \futurelet 39 40 \read 41 \font 42 43 % Idea: redefine {,g,e,x}def, {,g}let, {count,dimen,...}def, and other ways of 44 % define control sequences to respect namespaces. This way we can track 45 % shadowing by users and other namespaces and appropriately return control 46 % sequences to their former definitions when namespaces are exited. 47 \def\newns[#1]{\ea\newtoks\begcs members:#1\endcs} 48 \def\@addns#1{% 49 \if!#1!\else 50 \gcslet{\@ns.\csstring#1}#1% 51 \global\begcs members:\@ns\endcs\ea{\the\begcs members:\@ns\endcs\\#1}% 52 \ea\@addns 53 \fi 54 } 55 \def\addns[#1]#2{\def\@ns{#1}\@addns#2{}} 56 \def\usens[#1]{% 57 \def\\##1{\letcs##1{#1.\csstring##1}}% 58 \the\begcs members:#1\endcs 59 } 60 \def\enterns[#1]{% 61 \def\\##1{\gletcs##1{#1.\csstring##1}}% 62 \the\begcs members:#1\endcs 63 } 64 \def\exitns[#1]{% 65 \def\\##1{\ea\ifx\begcs#1.\csstring##1\endcs##1\gundef##1\fi}% 66 \the\begcs members:#1\endcs 67 } 68 69 % \newns[myns] 70 % { 71 % \def\x{xxx} 72 % \def\y{yyy} 73 % \def\z{zzz} 74 % \addns[myns]{\x\y\z} 75 % } 76 % \enterns[myns] 77 % \x\y\z 78 % \exitns[myns] 79 80 81 % Some parse code: 82 83 \def\@optionalequalsB#1{\csA} 84 \def\@optionalequalsA{\if=\next\ea\@optionalequalsB\else\csA\fi} 85 \def\optionalequals#1{\def\csA{#1}\futurelet\next\@optionalequalsA}