\documentclass{acmart}

\usepackage{ifthen}
\usepackage{xifthen}

\newcommand{\defgn}[2][]{%
    \ifthenelse{\isempty{#2}}{%
        \warn{Ignoring empty argument to \char`\\defgt}%
    }{%
        \ifthenelse{\isempty{#1}}{\defgn[\defgnname{#2}]{#2}}{%
            \expandafter\newcommand\expandafter{\csname #1\endcsname}{\ensuremath{#2}}
        }%
    }%
}

\defgn[efunc]{f}

\begin{document}

\input{formalism}

\end{document}

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: t
%%% End:
