[NTG-context] Append to a commalist
Hello, Is there a smart way to create a commalist? I want to get the equivalent of \setparameter[namespace][listname={item1,item2,item3}] but be able to append one item at the time, like \append{namepace}{listname}{item1} \append{namepace}{listname}{item2} \append{namepace}{listname}{item3} I have tired this: \def\append#1#2#3{ \fullexpandoneargafter\doifemptyelse{\getvariable{#1}{#2}} {\edef\tmp{#3}} {\edef\tmp{\getvariable{#1}{#2},#3}} \setvariables[#1][#2={\tmp}]} but it only works for one list. Apparently \tmp is not expanded so when an item is appended to one list all other lists are affected. I have tried \expanded but got the message stack full. Any help would be greatly appreciated. /Fredrik Teknisk projektledare Ph.D. Complex Systems AcobiaFLUX AB [EMAIL PROTECTED] Tel: +46 (0) 31 722 48 11 Fax: +46 (0) 31 722 48 01 Mob: +46 (0) 733 27 92 41 www.acobiaflux.se ___ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Re: [NTG-context] Append to a commalist
Fredrik Sjunnesson wrote: Hello, Is there a smart way to create a commalist? I want to get the equivalent of \setparameter[namespace][listname={item1,item2,item3}] but be able to append one item at the time, like \append{namepace}{listname}{item1} \append{namepace}{listname}{item2} \append{namepace}{listname}{item3} I have tired this: \def\append#1#2#3{ \fullexpandoneargafter\doifemptyelse{\getvariable{#1}{#2}} {\edef\tmp{#3}} {\edef\tmp{\getvariable{#1}{#2},#3}} \setvariables[#1][#2={\tmp}]} but it only works for one list. Apparently \tmp is not expanded so when an item is appended to one list all other lists are affected. I have tried \expanded but got the message stack full. Any help would be greatly appreciated. \def\appendtovaluelist#1#2% {\ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\empty \expandafter\def\csname#1\endcsname{#2}% \else \expandafter\def\csname#1\expandafter \expandafter\expandafter\endcsname \expandafter\expandafter\expandafter{\csname#1\endcsname,#2}% \fi \else \expandafter\def\csname#1\endcsname{#2}% \fi} % saves an argument: \def\appendtovaluelist#1% {\ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\empty \expandafter\noappendtovaluelist \csname#1\expandafter\expandafter\expandafter\endcsname \else \expandafter\doappendtovaluelist \csname#1\expandafter\expandafter\expandafter\endcsname \fi \else \expandafter\noappendtovaluelist\csname#1\expandafter\endcsname \fi} \def\doappendtovaluelist#1#2{\expandafter\def\expandafter#1\expandafter{#1,#2}} \def\noappendtovaluelist#1#2{\def#1{#2}} \appendtovaluelist{mylist}{aap} \appendtovaluelist{mylist}{noot} \appendtovaluelist{mylist}{mies} \showvalue{mylist} - 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 - ___ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Re: [NTG-context] Append to a commalist
On Thu, 12 Oct 2006, Hans Hagen wrote: Fredrik Sjunnesson wrote: Hello, Is there a smart way to create a commalist? I want to get the equivalent of \setparameter[namespace][listname={item1,item2,item3}] but be able to append one item at the time, like \append{namepace}{listname}{item1} \append{namepace}{listname}{item2} \append{namepace}{listname}{item3} I have tired this: \def\append#1#2#3{ \fullexpandoneargafter\doifemptyelse{\getvariable{#1}{#2}} {\edef\tmp{#3}} {\edef\tmp{\getvariable{#1}{#2},#3}} \setvariables[#1][#2={\tmp}]} but it only works for one list. Apparently \tmp is not expanded so when an item is appended to one list all other lists are affected. I have tried \expanded but got the message stack full. Any help would be greatly appreciated. \def\appendtovaluelist#1#2% {\ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\empty \expandafter\def\csname#1\endcsname{#2}% \else \expandafter\def\csname#1\expandafter \expandafter\expandafter\endcsname \expandafter\expandafter\expandafter{\csname#1\endcsname,#2}% \fi \else \expandafter\def\csname#1\endcsname{#2}% \fi} % saves an argument: \def\appendtovaluelist#1% {\ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\empty \expandafter\noappendtovaluelist \csname#1\expandafter\expandafter\expandafter\endcsname \else \expandafter\doappendtovaluelist \csname#1\expandafter\expandafter\expandafter\endcsname \fi \else \expandafter\noappendtovaluelist\csname#1\expandafter\endcsname \fi} \def\doappendtovaluelist#1#2{\expandafter\def\expandafter#1\expandafter{#1,#2}} \def\noappendtovaluelist#1#2{\def#1{#2}} \appendtovaluelist{mylist}{aap} \appendtovaluelist{mylist}{noot} \appendtovaluelist{mylist}{mies} \showvalue{mylist} What is the difference between a commalist and a valuelist :-) \def\secondlist{} \appendtocommalist{aap} {\secondlist} \appendtocommalist{noot} {\secondlist} \appendtocommalist{mies} {\secondlist} \showvalue{secondlist} Aditya ___ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Re: [NTG-context] Append to a commalist
Aditya Mahajan wrote: On Thu, 12 Oct 2006, Hans Hagen wrote: Fredrik Sjunnesson wrote: Hello, Is there a smart way to create a commalist? I want to get the equivalent of \setparameter[namespace][listname={item1,item2,item3}] but be able to append one item at the time, like \append{namepace}{listname}{item1} \append{namepace}{listname}{item2} \append{namepace}{listname}{item3} I have tired this: \def\append#1#2#3{ \fullexpandoneargafter\doifemptyelse{\getvariable{#1}{#2}} {\edef\tmp{#3}} {\edef\tmp{\getvariable{#1}{#2},#3}} \setvariables[#1][#2={\tmp}]} but it only works for one list. Apparently \tmp is not expanded so when an item is appended to one list all other lists are affected. I have tried \expanded but got the message stack full. Any help would be greatly appreciated. \def\appendtovaluelist#1#2% {\ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\empty \expandafter\def\csname#1\endcsname{#2}% \else \expandafter\def\csname#1\expandafter \expandafter\expandafter\endcsname \expandafter\expandafter\expandafter{\csname#1\endcsname,#2}% \fi \else \expandafter\def\csname#1\endcsname{#2}% \fi} % saves an argument: \def\appendtovaluelist#1% {\ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\empty \expandafter\noappendtovaluelist \csname#1\expandafter\expandafter\expandafter\endcsname \else \expandafter\doappendtovaluelist \csname#1\expandafter\expandafter\expandafter\endcsname \fi \else \expandafter\noappendtovaluelist\csname#1\expandafter\endcsname \fi} \def\doappendtovaluelist#1#2{\expandafter\def\expandafter#1\expandafter{#1,#2}} \def\noappendtovaluelist#1#2{\def#1{#2}} \appendtovaluelist{mylist}{aap} \appendtovaluelist{mylist}{noot} \appendtovaluelist{mylist}{mies} \showvalue{mylist} What is the difference between a commalist and a valuelist :-) \def\secondlist{} \appendtocommalist{aap} {\secondlist} \appendtocommalist{noot} {\secondlist} \appendtocommalist{mies} {\secondlist} \showvalue{secondlist} nothing, just the {name} thing -) -- - 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 - ___ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context
Re: [NTG-context] Append to a commalist
Great! Thank you very much Hans. It would have taken me a lifetime to get there :) /Fredrik -Ursprungligt meddelande- Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För Hans Hagen Skickat: den 12 oktober 2006 15:49 Till: mailing list for ConTeXt users Ämne: Re: [NTG-context] Append to a commalist Fredrik Sjunnesson wrote: Hello, Is there a smart way to create a commalist? I want to get the equivalent of \setparameter[namespace][listname={item1,item2,item3}] but be able to append one item at the time, like \append{namepace}{listname}{item1} \append{namepace}{listname}{item2} \append{namepace}{listname}{item3} I have tired this: \def\append#1#2#3{ \fullexpandoneargafter\doifemptyelse{\getvariable{#1}{#2}} {\edef\tmp{#3}} {\edef\tmp{\getvariable{#1}{#2},#3}} \setvariables[#1][#2={\tmp}]} but it only works for one list. Apparently \tmp is not expanded so when an item is appended to one list all other lists are affected. I have tried \expanded but got the message stack full. Any help would be greatly appreciated. \def\appendtovaluelist#1#2% {\ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\empty \expandafter\def\csname#1\endcsname{#2}% \else \expandafter\def\csname#1\expandafter \expandafter\expandafter\endcsname \expandafter\expandafter\expandafter{\csname#1\endcsname,#2}% \fi \else \expandafter\def\csname#1\endcsname{#2}% \fi} % saves an argument: \def\appendtovaluelist#1% {\ifcsname#1\endcsname \expandafter\ifx\csname#1\endcsname\empty \expandafter\noappendtovaluelist \csname#1\expandafter\expandafter\expandafter\endcsname \else \expandafter\doappendtovaluelist \csname#1\expandafter\expandafter\expandafter\endcsname \fi \else \expandafter\noappendtovaluelist\csname#1\expandafter\endcsname \fi} \def\doappendtovaluelist#1#2{\expandafter\def\expandafter#1\expandafter{#1,#2}} \def\noappendtovaluelist#1#2{\def#1{#2}} \appendtovaluelist{mylist}{aap} \appendtovaluelist{mylist}{noot} \appendtovaluelist{mylist}{mies} \showvalue{mylist} - 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 - ___ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context ___ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context