ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* How to \processcommalist inside another commalist?
@ 2006-08-21 15:23 Mojca Miklavec
  2006-08-21 17:17 ` nico
  0 siblings, 1 reply; 11+ messages in thread
From: Mojca Miklavec @ 2006-08-21 15:23 UTC (permalink / raw)


Hello,

I tried to print out primes (well, I tried to do something else, but I
needed a more illustrative example), but it seems that my approach was
too naive:

\def\arePrime[#1]{%
	\bgroup
	\getparameters[Prime][p=,#1]
	\def\printPrime##1{##1 is prime.\crlf}
	\processcommalist[\Primep]\printPrime
	\egroup}

\starttext
\arePrime[p={2,3,5}]
\stoptext

I expected something like
   2 is prime.
   3 is prime.
   5 is prime.
But I got
   2,3,5 is prime.

Any suggestions or hints about how to change the macro to produce the
desired result (using the same input)?

Thank you a lot,
    Mojca

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 15:23 How to \processcommalist inside another commalist? Mojca Miklavec
@ 2006-08-21 17:17 ` nico
  2006-08-21 18:07   ` Taco Hoekwater
  2006-08-21 18:35   ` Mojca Miklavec
  0 siblings, 2 replies; 11+ messages in thread
From: nico @ 2006-08-21 17:17 UTC (permalink / raw)


On Mon, 21 Aug 2006 17:23:48 +0200, Mojca Miklavec  
<mojca.miklavec.lists@gmail.com> wrote:

> Hello,
>
> I tried to print out primes (well, I tried to do something else, but I
> needed a more illustrative example), but it seems that my approach was
> too naive:
>
> \def\arePrime[#1]{%
> 	\bgroup
> 	\getparameters[Prime][p=,#1]
> 	\def\printPrime##1{##1 is prime.\crlf}
> 	\processcommalist[\Primep]\printPrime
> 	\egroup}
>
> \starttext
> \arePrime[p={2,3,5}]
> \stoptext

My 2 cents contribution:

\def\printPrime#1{#1 is prime.\crlf}

%% Why using parameter for this?
\def\arePrime[#1]{%
\bgroup
\processcommalist[#1]\printPrime
\egroup}

%% Expand the parameter before processing
\def\arePrimeN[#1]{%
\bgroup
\getparameters[Prime][p=,#1]
\expandafter\processcommalist\expandafter[\Primep]\printPrime
\egroup}

\starttext
\arePrime[2,3,5]
\arePrimeN[p={2,3,5}]
\stoptext

Regards,
BG

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 17:17 ` nico
@ 2006-08-21 18:07   ` Taco Hoekwater
  2006-08-21 18:35   ` Mojca Miklavec
  1 sibling, 0 replies; 11+ messages in thread
From: Taco Hoekwater @ 2006-08-21 18:07 UTC (permalink / raw)


nico wrote:
> \def\arePrimeN[#1]{%
> \bgroup
> \getparameters[Prime][p=,#1]
> \expandafter\processcommalist\expandafter[\Primep]\printPrime
> \egroup}

And an equivalent is

   \processcommacommand[\Primep]\printPrime

Cheers,
Taco

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 17:17 ` nico
  2006-08-21 18:07   ` Taco Hoekwater
@ 2006-08-21 18:35   ` Mojca Miklavec
  2006-08-21 20:51     ` nico
                       ` (2 more replies)
  1 sibling, 3 replies; 11+ messages in thread
From: Mojca Miklavec @ 2006-08-21 18:35 UTC (permalink / raw)


On 8/21/06, nico wrote:
> On Mon, 21 Aug 2006 17:23:48 +0200, Mojca Miklavec wrote:
>
> > Hello,
> >
> > I tried to print out primes (well, I tried to do something else, but I
> > needed a more illustrative example), but it seems that my approach was
> > too naive:
> >
> > \def\arePrime[#1]{%
> >       \bgroup
> >       \getparameters[Prime][p=,#1]
> >       \def\printPrime##1{##1 is prime.\crlf}
> >       \processcommalist[\Primep]\printPrime
> >       \egroup}
> >
> > \starttext
> > \arePrime[p={2,3,5}]
> > \stoptext
>
> My 2 cents contribution:
>
> \def\printPrime#1{#1 is prime.\crlf}
>
> %% Why using parameter for this?

I was sure that someone would ask that. I want to provide optional
parameters for both numbers and scaling:
    \useGNUPLOTgraphic[name]
or
    \useGNUPLOTgraphic[name][width=.9\textwidth]
or
    \useGNUPLOTgraphic[name][n={1,3}]
or
    \useGNUPLOTgraphic[name][n={1,3},width=.9\textwidth]

but after some thinking I realized that it would indeed be a better
idea (less to type?) to have
    \useGNUPLOTgraphic[name][1,3]
and
    \useGNUPLOTgraphic[name][1,3][width=.9\textwidth]
instead.

At the beginning the main reason against it was that I didn't know how
to distinguish which kind of parameters are being used in the second
pair of brackets, but I guess that I can safely use \ifnumberelse as a
test on the first item to distinguish between the two.

> %% Expand the parameter before processing
> \def\arePrimeN[#1]{%
> \bgroup
> \getparameters[Prime][p=,#1]
> \expandafter\processcommalist\expandafter[\Primep]\printPrime
> \egroup}

On 8/21/06, Taco Hoekwater wrote:
> And an equivalent is
>
>    \processcommacommand[\Primep]\printPrime

Thanks to both of you!

Mojca

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 18:35   ` Mojca Miklavec
@ 2006-08-21 20:51     ` nico
  2006-08-21 21:08       ` Hans Hagen
  2006-08-21 21:04     ` Taco Hoekwater
  2006-08-21 21:04     ` Hans Hagen
  2 siblings, 1 reply; 11+ messages in thread
From: nico @ 2006-08-21 20:51 UTC (permalink / raw)


On Mon, 21 Aug 2006 20:35:27 +0200, Mojca Miklavec  
<mojca.miklavec.lists@gmail.com> wrote:

>> %% Why using parameter for this?
>
> I was sure that someone would ask that. I want to provide optional
> parameters for both numbers and scaling:
>     \useGNUPLOTgraphic[name]
> or
>     \useGNUPLOTgraphic[name][width=.9\textwidth]
> or
>     \useGNUPLOTgraphic[name][n={1,3}]
> or
>     \useGNUPLOTgraphic[name][n={1,3},width=.9\textwidth]
>
> but after some thinking I realized that it would indeed be a better
> idea (less to type?) to have
>     \useGNUPLOTgraphic[name][1,3]
> and
>     \useGNUPLOTgraphic[name][1,3][width=.9\textwidth]
> instead.
>
> At the beginning the main reason against it was that I didn't know how
> to distinguish which kind of parameters are being used in the second
> pair of brackets, but I guess that I can safely use \ifnumberelse as a
> test on the first item to distinguish between the two.

Maybe you could play only with the parameter count. The limitation is that  
an empty second argument is required when only options need to be passed.

\def\printPrime#1{#1 is prime.\crlf}

\def\useGNUPLOTgraphic
   {\dotripleempty\douseGNUPLOTgraphic}

\def\douseGNUPLOTgraphic[#1][#2][#3]%
   {\ifthirdargument
      \doprime{#2}
      parameters are #3
      \getparameters[gnuplot][#3]
    \else\ifsecondargument
      \doprime{#2}
    \fi\fi}

\def\doprime#1{\processcommalist[#1]\printPrime}

\starttext
\useGNUPLOTgraphic[name]
\useGNUPLOTgraphic[name][2,3,5]
\useGNUPLOTgraphic[name][3,5,7][width=2in]
\useGNUPLOTgraphic[name][][width=4in]
\stoptext

Regards,
BG

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 18:35   ` Mojca Miklavec
  2006-08-21 20:51     ` nico
@ 2006-08-21 21:04     ` Taco Hoekwater
  2006-08-23 20:43       ` Mojca Miklavec
  2006-08-21 21:04     ` Hans Hagen
  2 siblings, 1 reply; 11+ messages in thread
From: Taco Hoekwater @ 2006-08-21 21:04 UTC (permalink / raw)


Mojca Miklavec wrote:
> 
> At the beginning the main reason against it was that I didn't know how
> to distinguish which kind of parameters are being used in the second
> pair of brackets, but I guess that I can safely use \ifnumberelse as a
> test on the first item to distinguish between the two.

You could look up \doifassignmentelse in the sources.

Cheers, taco

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 18:35   ` Mojca Miklavec
  2006-08-21 20:51     ` nico
  2006-08-21 21:04     ` Taco Hoekwater
@ 2006-08-21 21:04     ` Hans Hagen
  2 siblings, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2006-08-21 21:04 UTC (permalink / raw)


Mojca Miklavec wrote:
> On 8/21/06, nico wrote:
>   
>> On Mon, 21 Aug 2006 17:23:48 +0200, Mojca Miklavec wrote:
>>
>>     
>>> Hello,
>>>
>>> I tried to print out primes (well, I tried to do something else, but I
>>> needed a more illustrative example), but it seems that my approach was
>>> too naive:
>>>
>>> \def\arePrime[#1]{%
>>>       \bgroup
>>>       \getparameters[Prime][p=,#1]
>>>       \def\printPrime##1{##1 is prime.\crlf}
>>>       \processcommalist[\Primep]\printPrime
>>>       \egroup}
>>>
>>> \starttext
>>> \arePrime[p={2,3,5}]
>>> \stoptext
>>>       
>> My 2 cents contribution:
>>
>> \def\printPrime#1{#1 is prime.\crlf}
>>
>> %% Why using parameter for this?
>>     
>
> I was sure that someone would ask that. I want to provide optional
> parameters for both numbers and scaling:
>     \useGNUPLOTgraphic[name]
> or
>     \useGNUPLOTgraphic[name][width=.9\textwidth]
> or
>     \useGNUPLOTgraphic[name][n={1,3}]
> or
>     \useGNUPLOTgraphic[name][n={1,3},width=.9\textwidth]
>
> but after some thinking I realized that it would indeed be a better
> idea (less to type?) to have
>     \useGNUPLOTgraphic[name][1,3]
> and
>     \useGNUPLOTgraphic[name][1,3][width=.9\textwidth]
> instead.
>
>   
along these lines:

\def\useGNUPLOTgraphic
  {\dotripleempty\douseGNUPLOTgraphic}

\def\douseGNUPLOTgraphic[#1][#2][#3]%
   {\itthirdargument
        \dodouseGNUPLOTgraphic[#1][#2][#3]%
    \else\ifsecondargument
        \def\docommand##1{\dodouseGNUPLOTgraphic[#1][##1][#3]}%
        \processcommalist[#2]\docommand
   \fi}

\def\dodouseGNUPLOTgraphic[#1][#2][#3]%
   {\getparameters[#1:#2][#3]}

etc etc

you can also check for \doifsssignmentelse{#2}{...}{...}
> At the beginning the main reason against it
Hans

-- 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 20:51     ` nico
@ 2006-08-21 21:08       ` Hans Hagen
  2006-08-21 22:26         ` nico
  0 siblings, 1 reply; 11+ messages in thread
From: Hans Hagen @ 2006-08-21 21:08 UTC (permalink / raw)


nico wrote:
> On Mon, 21 Aug 2006 20:35:27 +0200, Mojca Miklavec  
> <mojca.miklavec.lists@gmail.com> wrote:
>
>   
>>> %% Why using parameter for this?
>>>       
>> I was sure that someone would ask that. I want to provide optional
>> parameters for both numbers and scaling:
>>     \useGNUPLOTgraphic[name]
>> or
>>     \useGNUPLOTgraphic[name][width=.9\textwidth]
>> or
>>     \useGNUPLOTgraphic[name][n={1,3}]
>> or
>>     \useGNUPLOTgraphic[name][n={1,3},width=.9\textwidth]
>>
>> but after some thinking I realized that it would indeed be a better
>> idea (less to type?) to have
>>     \useGNUPLOTgraphic[name][1,3]
>> and
>>     \useGNUPLOTgraphic[name][1,3][width=.9\textwidth]
>> instead.
>>
>> At the beginning the main reason against it was that I didn't know how
>> to distinguish which kind of parameters are being used in the second
>> pair of brackets, but I guess that I can safely use \ifnumberelse as a
>> test on the first item to distinguish between the two.
>>     
>
> Maybe you could play only with the parameter count. The limitation is that  
> an empty second argument is required when only options need to be passed.
>   
why? in that case #3 is empty and #2 contains the options
> \def\printPrime#1{#1 is prime.\crlf}
>
> \def\useGNUPLOTgraphic
>    {\dotripleempty\douseGNUPLOTgraphic}
>
> \def\douseGNUPLOTgraphic[#1][#2][#3]%
>    {\ifthirdargument
>       \doprime{#2}
>       parameters are #3
>       \getparameters[gnuplot][#3]
>     \else\ifsecondargument
>       \doprime{#2}
>     \fi\fi}
>
> \def\doprime#1{\processcommalist[#1]\printPrime}
>
> \starttext
> \useGNUPLOTgraphic[name]
> \useGNUPLOTgraphic[name][2,3,5]
> \useGNUPLOTgraphic[name][3,5,7][width=2in]
> \useGNUPLOTgraphic[name][][width=4in]
> \stoptext
>
> Regards,
> BG
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>   


-- 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 21:08       ` Hans Hagen
@ 2006-08-21 22:26         ` nico
  2006-08-22  8:13           ` Hans Hagen
  0 siblings, 1 reply; 11+ messages in thread
From: nico @ 2006-08-21 22:26 UTC (permalink / raw)


On Mon, 21 Aug 2006 23:08:59 +0200, Hans Hagen <pragma@wxs.nl> wrote:

>>> but after some thinking I realized that it would indeed be a better
>>> idea (less to type?) to have
>>>     \useGNUPLOTgraphic[name][1,3]
>>> and
>>>     \useGNUPLOTgraphic[name][1,3][width=.9\textwidth]
>>> instead.
>>>
>>> At the beginning the main reason against it was that I didn't know how
>>> to distinguish which kind of parameters are being used in the second
>>> pair of brackets, but I guess that I can safely use \ifnumberelse as a
>>> test on the first item to distinguish between the two.
>>>
>>
>> Maybe you could play only with the parameter count. The limitation is  
>> that
>> an empty second argument is required when only options need to be  
>> passed.
>>
> why? in that case #3 is empty and #2 contains the options

Hm, I thought that the initial goal was to know if the parameter passed is  
a number list, or an option list. In the suggested code, the assumption is  
that the number list (if any) is always the second parameter.

If not, how to handle those cases?

\useGNUPLOTgraphic[name][2,3,5]
\useGNUPLOTgraphic[name][width=2in]

But I guess there are clever internal macros that could help :-)

Regards,
BG

>> \def\printPrime#1{#1 is prime.\crlf}
>>
>> \def\useGNUPLOTgraphic
>>    {\dotripleempty\douseGNUPLOTgraphic}
>>
>> \def\douseGNUPLOTgraphic[#1][#2][#3]%
>>    {\ifthirdargument
>>       \doprime{#2}
>>       parameters are #3
>>       \getparameters[gnuplot][#3]
>>     \else\ifsecondargument
>>       \doprime{#2}
>>     \fi\fi}
>>
>> \def\doprime#1{\processcommalist[#1]\printPrime}
>>
>> \starttext
>> \useGNUPLOTgraphic[name]
>> \useGNUPLOTgraphic[name][2,3,5]
>> \useGNUPLOTgraphic[name][3,5,7][width=2in]
>> \useGNUPLOTgraphic[name][][width=4in]
>> \stoptext

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 22:26         ` nico
@ 2006-08-22  8:13           ` Hans Hagen
  0 siblings, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2006-08-22  8:13 UTC (permalink / raw)


nico wrote:
> On Mon, 21 Aug 2006 23:08:59 +0200, Hans Hagen <pragma@wxs.nl> wrote:
>
>   
>>>> but after some thinking I realized that it would indeed be a better
>>>> idea (less to type?) to have
>>>>     \useGNUPLOTgraphic[name][1,3]
>>>> and
>>>>     \useGNUPLOTgraphic[name][1,3][width=.9\textwidth]
>>>> instead.
>>>>
>>>> At the beginning the main reason against it was that I didn't know how
>>>> to distinguish which kind of parameters are being used in the second
>>>> pair of brackets, but I guess that I can safely use \ifnumberelse as a
>>>> test on the first item to distinguish between the two.
>>>>
>>>>         
>>> Maybe you could play only with the parameter count. The limitation is  
>>> that
>>> an empty second argument is required when only options need to be  
>>> passed.
>>>
>>>       
>> why? in that case #3 is empty and #2 contains the options
>>     
>
> Hm, I thought that the initial goal was to know if the parameter passed is  
> a number list, or an option list. In the suggested code, the assumption is  
> that the number list (if any) is always the second parameter.
>
> If not, how to handle those cases?
>
> \useGNUPLOTgraphic[name][2,3,5]
> \useGNUPLOTgraphic[name][width=2in]
>
> But I guess there are clever internal macros that could help :-)
>   
as already mentioned: \doifassignmentelse{#2}{...}{...}

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

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

* Re: How to \processcommalist inside another commalist?
  2006-08-21 21:04     ` Taco Hoekwater
@ 2006-08-23 20:43       ` Mojca Miklavec
  0 siblings, 0 replies; 11+ messages in thread
From: Mojca Miklavec @ 2006-08-23 20:43 UTC (permalink / raw)


On 8/21/06, Taco Hoekwater wrote:
> nico wrote:
> > \def\arePrimeN[#1]{%
> > \bgroup
> > \getparameters[Prime][p=,#1]
> > \expandafter\processcommalist\expandafter[\Primep]\printPrime
> > \egroup}
>
> And an equivalent is
>
>    \processcommacommand[\Primep]\printPrime

On 8/21/06, Taco Hoekwater wrote:
> Mojca Miklavec wrote:
> >
> > At the beginning the main reason against it was that I didn't know how
> > to distinguish which kind of parameters are being used in the second
> > pair of brackets, but I guess that I can safely use \ifnumberelse as a
> > test on the first item to distinguish between the two.
>
> You could look up \doifassignmentelse in the sources.

Thank you, the two commands (including Hans's additional hints) solved
"all" my questions (for now.)

Mojca

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

end of thread, other threads:[~2006-08-23 20:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-21 15:23 How to \processcommalist inside another commalist? Mojca Miklavec
2006-08-21 17:17 ` nico
2006-08-21 18:07   ` Taco Hoekwater
2006-08-21 18:35   ` Mojca Miklavec
2006-08-21 20:51     ` nico
2006-08-21 21:08       ` Hans Hagen
2006-08-21 22:26         ` nico
2006-08-22  8:13           ` Hans Hagen
2006-08-21 21:04     ` Taco Hoekwater
2006-08-23 20:43       ` Mojca Miklavec
2006-08-21 21:04     ` Hans Hagen

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).