I would use a completely different approach, with a key-value syntax. Six arguments, some of them optional, with a *
to denote a missing one are error prone.
\documentclass{article}
\usepackage{amsmath,keyval}
\makeatletter
\newcommand{\funcdef@key}[1]{%
\define@key{funcdef}{#1}{\@namedef{cet@#1}{##1}}%
\expandafter\let\csname cet@#1\endcsname\@empty
}
\funcdef@key{name}
\funcdef@key{domain}
\funcdef@key{codomain}
\funcdef@key{variable}
\funcdef@key{notation}
\funcdef@key{definition}
\newcommand{\funcdef@check}[1]{%
\expandafter\ifx\csname cet@#1\endcsname\@empty
\@latex@error{Missing `#1'}{Provide `#1'}%
\fi
}
\newcommand{\funcdef}[1]{%
\begingroup
\setkeys{funcdef}{#1}%
\ifx\cet@codomain\@empty\let\cet@codomain\cet@domain\fi
\funcdef@check{name}%
\funcdef@check{domain}%
\funcdef@check{variable}%
\begin{array}{l@{}r@{}l@{}l}
\cet@name\colon{} &
\cet@domain &
{}\to \cet@codomain \\
&
\cet@variable &
{}\mapsto
\ifx\cet@notation\@empty
\cet@name(\cet@variable)
\else
\cet@notation
\fi
\ifx\cet@definition\@empty
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{& {}\mathrel{:}=\cet@definition}
\\
\end{array}
\endgroup
}
\makeatletter
\begin{document}
\noindent
Simple function:
\[
\funcdef{name=f,variable=x,domain=\mathbf{R}}
\]
Simple function with declaration:
\[
\funcdef{
name=f,
variable=x,
domain=\mathbf{R},
notation=x^2
}
\]
Function with alternative writing:
\[
\funcdef{
name=\exp,
variable=x,
domain=\mathbf{R},
notation=e^x
}
\]
Function with alternative writing and declaration:
\[
\funcdef{
name=\exp,
variable=x,
domain=\mathbf{R},
notation=e^x,
definition=\lim\limits_{n\to\infty}\left(1+\frac xn\right)^n
}
\]
Function with different domain and codomain:
\[
\funcdef{
name=\operatorname{sqrt},
variable=n,
domain=\mathbf{N},
codomain=\mathbf{R}
}
\]
Function with different domain and codomain, and alternative
writing:
\[
\funcdef{
name=\operatorname{sqrt},
variable=n,
domain=\mathbf{N},
codomain=\mathbf{R},
definition=\sqrt{n}
}
\]
Function with different domain and codomain, alternative writing
and declaration:
\[
\funcdef{
name=\operatorname{sqrt},
variable=n,
domain=\mathbf{N},
codomain=\mathbf{R},
notation=\sqrt{n},
definition=\exp\bigl(\frac{1}{2}\ln n\bigr)
}
\]
\end{document}

Here's an implementation in LaTeX3, with also an “inline” version.
\documentclass{article}
\usepackage{amsmath,xparse}
\ExplSyntaxOn
\keys_define:nn { funcdef }
{
name .tl_set:N = \l_funcdef_name_tl,
name .initial:n = {},
domain .tl_set:N = \l_funcdef_domain_tl,
domain .initial:n = {},
codomain .tl_set:N = \l_funcdef_codomain_tl,
codomain .initial:n = {},
variable .tl_set:N = \l_funcdef_variable_tl,
variable .initial:n = {},
variables .tl_set:N = \l_funcdef_variables_tl,
variables .initial:n = {},
notation .tl_set:N = \l_funcdef_notation_tl,
notation .initial:n = {},
definition .tl_set:N = \l_funcdef_definition_tl,
definition .initial:n = {},
inline .bool_set:N = \l_funcdef_inline_bool,
}
\msg_new:nnnn { funcdef } { missing }
{
Missing~`#1'
}
{
You~have~to~specify~a~value~for~`#1';~%
I~have~substituted~??~for~it
}
\NewDocumentCommand{\funcdef}{ m }
{
\group_begin:
\funcdef_print:n { #1 }
\group_end:
}
\cs_new_protected:Npn \funcdef_print:n #1
{
\keys_set:nn { funcdef } { #1 }
\funcdef_check:n { name }
\funcdef_check:n { domain }
\tl_if_empty:NT \l_funcdef_variables_tl
{
\funcdef_check:n { variable }
}
\tl_if_empty:NT \l_funcdef_codomain_tl
{
\tl_set_eq:NN \l_funcdef_codomain_tl \l_funcdef_domain_tl
}
\bool_if:NTF \l_funcdef_inline_bool
{
\funcdef_print_inline:
}
{
\funcdef_print_array:
}
}
\cs_new_protected:Npn \funcdef_print_array:
{
\begin{array}{ l @{} r @{} l }
% first row
\l_funcdef_name_tl \colon {}
&
\l_funcdef_domain_tl
&
{}\to \l_funcdef_codomain_tl
\\
% second row
&
\tl_if_empty:NTF \l_funcdef_variable_tl
{
(\l_funcdef_variables_tl)
}
{
\l_funcdef_variable_tl
}
&
{}\mapsto
\tl_if_empty:NTF \l_funcdef_notation_tl
{
\l_funcdef_name_tl (
\tl_if_empty:NTF \l_funcdef_variable_tl
{
\l_funcdef_variables_tl
}
{
\l_funcdef_variable_tl
}
)
}
{
\l_funcdef_notation_tl
}
\tl_if_empty:NF \l_funcdef_definition_tl
{ \mathrel{:}= \l_funcdef_definition_tl }
\\
\end{array}
}
\cs_new:Npn \funcdef_print_inline:
{
\l_funcdef_name_tl \colon
\l_funcdef_domain_tl
\to \l_funcdef_codomain_tl
,\quad
\tl_if_empty:NTF \l_funcdef_variable_tl
{
(\l_funcdef_variables_tl)
}
{
\l_funcdef_variable_tl
}
\mapsto
\tl_if_empty:NTF \l_funcdef_notation_tl
{
\l_funcdef_name_tl (
\tl_if_empty:NTF \l_funcdef_variable_tl
{
\l_funcdef_variables_tl
}
{
\l_funcdef_variable_tl
}
)
}
{
\l_funcdef_notation_tl
}
\tl_if_empty:NF \l_funcdef_definition_tl
{ \mathrel{:}= \l_funcdef_definition_tl }
}
\cs_new_protected:Npn \funcdef_check:n #1
{
\tl_if_empty:cT { l_funcdef_#1_tl }
{
\msg_error:nnn { funcdef } { missing } { #1 }
\tl_set:cn { l_funcdef_#1_tl } { ?? }
}
}
\ExplSyntaxOff
\begin{document}
\noindent
Simple function inline:
\[
\funcdef{inline,name=f,variable=x,domain=\mathbf{R}}
\]
Simple function:
\[
\funcdef{name=f,variable=x,domain=\mathbf{R}}
\]
Simple function with declaration:
\[
\funcdef{
name=f,
variable=x,
domain=\mathbf{R},
definition=x^2
}
\]
Function with alternative writing:
\[
\funcdef{
name=\exp,
variable=x,
domain=\mathbf{R},
notation=e^x
}
\]
Function with alternative writing and declaration:
\[
\funcdef{
name=\exp,
variable=x,
domain=\mathbf{R},
notation=e^x,
definition=\lim\limits_{n\to\infty}\left(1+\frac xn\right)^n
}
\]
Function with different domain and codomain:
\[
\funcdef{
name=\operatorname{sqrt},
variable=n,
domain=\mathbf{N},
codomain=\mathbf{R}
}
\]
Function with different domain and codomain, and alternative
writing:
\[
\funcdef{
name=\operatorname{sqrt},
variable=n,
domain=\mathbf{N},
codomain=\mathbf{R},
definition=\sqrt{n}
}
\]
Function with different domain and codomain, alternative writing
and declaration:
\[
\funcdef{
name=\operatorname{sqrt},
variable=n,
domain=\mathbf{N},
codomain=\mathbf{R},
notation=\sqrt{n},
definition=\exp\bigl(\frac{1}{2}\ln n\bigr)
}
\]
Function of two variables:
\[
\funcdef{
name=f,
variables={a,b},
domain=A\times B,
codomain=C,
}
\]
\end{document}

\DeclareDocumentCommand\funcdef{mmomsoo}{
...}
?\IfValueTF{#3}{<true code>}{<false code>}
to test whether the optional argument#3
has a value, and\IfBooleanTF{#5}{<star there>}{<star absent>}
for the star. I agree with daleif that the source is not readable. Perhaps a key--value syntax would be clearer?