ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Problem with macro with optional parameter
@ 2017-06-27  8:58 Jaroslav Hajtmar
  2017-06-27 11:05 ` Henri Menke
  0 siblings, 1 reply; 3+ messages in thread
From: Jaroslav Hajtmar @ 2017-06-27  8:58 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 897 bytes --]

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


\stoptext

[-- Attachment #1.2: Type: text/html, Size: 5516 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with macro with optional parameter
  2017-06-27  8:58 Problem with macro with optional parameter Jaroslav Hajtmar
@ 2017-06-27 11:05 ` Henri Menke
  2017-06-27 11:25   ` Jaroslav Hajtmar
  0 siblings, 1 reply; 3+ messages in thread
From: Henri Menke @ 2017-06-27 11:05 UTC (permalink / raw)
  To: ntg-context

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
> ___________________________________________________________________________________
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with macro with optional parameter
  2017-06-27 11:05 ` Henri Menke
@ 2017-06-27 11:25   ` Jaroslav Hajtmar
  0 siblings, 0 replies; 3+ messages in thread
From: Jaroslav Hajtmar @ 2017-06-27 11:25 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Thanx Henri for answer.
Maybe I have been explaining wrong my problem. I would need a variant without a parameter and concurrently without braces. Command without braces swallows the break of the paragraph.

\def\Command#1%
  {\expdoifelse{#1}{}{100}{#1}}

\starttext

1. \Command{5} % OK

2. \Command  % OK

3. As You see, Command without braces swallows the break of the paragraph.

1. \dorecurse{\Command{5}}{\recurselevel\crlf} % not working

2. \dorecurse{\Command{}}{\recurselevel\crlf}  % not working

\stoptext


Jaroslav Hajtmar





Dne 27.06.17 13:05, ntg-context za uživatele Henri Menke <ntg-context-bounces@ntg.nl za uživatele henrimenke@gmail.com> napsal(a):

    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
    > ___________________________________________________________________________________
    ___________________________________________________________________________________
    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
    ___________________________________________________________________________________

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-27 11:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27  8:58 Problem with macro with optional parameter Jaroslav Hajtmar
2017-06-27 11:05 ` Henri Menke
2017-06-27 11:25   ` Jaroslav Hajtmar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).