ai2472206...@yeah.net schrieb am 22.10.2024 um 07:32:
Thank you so much. I think I understand its usage.

Also, regarding the "ifargument" command you mentioned,
is it counting from 0 and then checking the arguments one by one?
Because I only learned "iffirstargument", "ifsecondargument" from the wiki.
Perhaps we should update the section on the wiki on defining optional 
parameters.


You can check individual argument with the old and new method but there are differences because the new \ifparameter conditional gives a false result when you set the optional argument but leave it empty.

%%%% begin example
\def\oldargumentcheck
  {\dotripleempty\dooldargumentcheck}

\def\dooldargumentcheck[#1][#2][#3]%
  {\iffirstargument
     First optional argument is used.\par
   \else
     First optional argument isn't used.\par
   \fi
   \ifsecondargument
     Second optional argument is used.\par
   \else
     Second optional argument isn't used.\par
   \fi
   \ifthirdargument
     Third optional argument is used.\par
   \else
     Third optional argument isn't used.\par
   \fi}

\tolerant\def\newargumentcheck[#1][#2][#3]%
  {\ifparameter#1\or
     First optional argument is used.\par
   \else
     First optional argument isn't used or empty.\par
   \fi
   \ifparameter#2\or
     Second optional argument is used.\par
   \else
     Second optional argument isn't used or empty.\par
   \fi
   \ifparameter#3\or
     Third optional argument is used.\par
   \else
     Third optional argument isn't used or empty.\par
   \fi}

\starttext

\oldargumentcheck[][foo]

\blank

\newargumentcheck[][bar]

\stoptext
%%%% end example

When you care only about the number of argument you would use nested argument checks in the old system but the new \ifarguments conditional uses branches for each case like \ifcase. The order for the number of arguments is also reversed, the old system starts with the case for all argument and ends with zero arguments while the new check start with zero arguments and ends with all of them.

%%%% begin example
\def\oldcommand
  {\dotripleempty\dooldcommand}

\def\dooldcommand[#1][#2][#3]%
  {\ifthirdargument
     Three optional arguments are used.\par
   \else\ifsecondargument
     Two optional arguments are used.\par
   \else\iffirstargument
     One optional argument is used.\par
   \else
     No optional argument is used.\par
   \fi\fi\fi}

\tolerant\def\newcommand[#1][#2][#3]%
  {\ifarguments
     No optional argument is used.\par
   \or
     One optional argument is used.\par
   \or
     Two optional arguments are used.\par
   \or
     Three optional arguments are used.\par
   \fi}

\starttext

\oldcommand[][]

\blank

\newcommand[][]

\stoptext
%%%% end example

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to