How to \processcommalist inside another commalist?
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
On Mon, 21 Aug 2006 17:23:48 +0200, Mojca Miklavec
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
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
On Mon, 21 Aug 2006 20:35:27 +0200, Mojca Miklavec
%% 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
nico wrote:
On Mon, 21 Aug 2006 20:35:27 +0200, Mojca Miklavec
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 -----------------------------------------------------------------
On Mon, 21 Aug 2006 23:08:59 +0200, Hans Hagen
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
nico wrote:
On Mon, 21 Aug 2006 23:08:59 +0200, Hans Hagen
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 -----------------------------------------------------------------
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
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
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 -----------------------------------------------------------------
participants (4)
-
Hans Hagen
-
Mojca Miklavec
-
nico
-
Taco Hoekwater