olsak / OpTeX

OpTeX - LuaTeX format with extended Plain TeX macros
http://petr.olsak.net/optex/
35 stars 14 forks source link

Unexpected behavior for \slet{foo}{\_undefined} #54

Closed robertbachmann closed 3 years ago

robertbachmann commented 3 years ago
\def\foo{...}
\let\foo=\_undefined
\meaning\foo { and} \meaning\_undefined
% OK: undefined and undefined

\def\foo{...}
\slet{foo}{_undefined}
\meaning\foo { and} \meaning\_undefined
%NOT OK: \relax and \relax

Proof of concept fix:

\_def \_slet #1#2{%
\_ifcsname #2\_endcsname%
\_ea\_let \_csname#1\_ea\_endcsname \_csname#2\_endcsname%
\_else%
\_ea\_let \_csname#1\_endcsname \_undefined%
\_fi%
}
\_public \slet ;

This fix is incomplete, for example \global\slet{x}{y} would not work anymore.

vlasakm commented 3 years ago

I found success with LuaTeX's \begincsname, which means that the check for existence is done twice, but no relaxed variant is created. I didn't find success with \lastnamedcs.


\fontfam[lm]
%\_def \_slet #1#2{\_ea\_let \_csname#1\_ea\_endcsname \_csname#2\_endcsname}
\_def \_slet #1#2{\_ea\_let \_csname#1\_ea\_endcsname
   \_ifcsname#2\_ea\_endcsname
      \_begincsname#2\_endcsname
   \_else
      \_undefined
   \_fi
}
\_public \slet ;

{
\def\foo{...}
\global\let\foo=\_undefined
\meaning\foo { and} \meaning\_undefined
% OK: undefined and undefined
}\par
\meaning\foo { and} \meaning\_undefined
% OK: undefined and undefined

{
\def\foo{...}
\global\slet{foo}{_undefined}
\meaning\foo { and} \meaning\_undefined
% OK: undefined and undefined
}\par
\meaning\foo { and} \meaning\_undefined
% OK: undefined and undefined

{
\def\foo{a}
\global\slet{bar}{foo}
\meaning\foo { and} \meaning\bar
}\par
\meaning\foo { and} \meaning\bar
% OK: undefined and macro:->a

\def\foo{...}
{
\let\foo\def
\global\slet{bar}{foo}
\meaning\foo { and} \meaning\bar
% OK: \def and \def
}\par
\meaning\foo { and} \meaning\bar
% OK: macro:->... and \def

\bye