![](https://secure.gravatar.com/avatar/60f3cc97f94fa3690ba406f8c1a7fc4f.jpg?s=120&d=mm&r=g)
On Tue, 2017-06-27 at 08:58 +0000, Jaroslav Hajtmar wrote:
Hello ConTeXist. I'm not able to solve a macros problem with one optional argument. I need the macro to return a value that can be used as a dorecurse loop parameter. Is there possibility create macro with optional parameter and parameter is concurrently inside in braces? (in nonsquare brackets)? I've tried to experiment with examples from the wiki, but I'm not clear about it. Thanx for help. Jaroslav Hajtmar Here is minimal example: \def\DoCommand[#1]% {\iffirstargument#1\else100\fi} \def\Command% {\dosingleargument\DoCommand} %\def\DoAnotherCommand{#1}% % {\iffirstargument#1\else100\fi} %\def\AnotherCommand% % {\dosingleargument\DoAnotherCommand} \starttext 1. \Command[5] % OK 2. \Command % OK %1. \dorecurse{\Command[5]}{\recurselevel\crlf} % not working %2. \dorecurse{\Command}{\recurselevel\crlf} % not working
The first argument to \dorecurse has to expand to a number. Therefore it has to be fully- expandable. Scanning for optional brackets is never expandable. You have to do it this way: \def\Command#1% {\expdoifelse{#1}{}{100}{#1}} \starttext 1. \Command{5} % OK 2. \Command{} % OK 1. \dorecurse{\Command{5}}{\recurselevel\crlf} % not working 2. \dorecurse{\Command{}}{\recurselevel\crlf} % not working \stoptext
\stoptext ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________