# Replicate similar structured macro definitions with LaTeX3

Is any posssibility create similar structured macro? For example, in MWE I have a \creator and I want create same defined macro \lecturer, so it possible via replacing word creator to lecturer. And if I have many identical same macro it is boring. I need to somehow define the listing at the program level, such creator, lecturer,practicer and then multiply the user level macros \creator, \lecturer, \practicer...

\documentclass{article}

\ExplSyntaxOn

\int_new:N \l_creator_int
\NewDocumentCommand\creator{ O{} m}
{
\int_incr:N \l_creator_int
\cs_new_protected:cpn {creator\int_use:N\l_creator_int}{#2}
\tl_if_empty:nTF {#1} {} {\cs_new_protected:cpn {creator\int_use:N\l_creator_int email}{#1}}

}

%\int_new:N \l_lecturer_int
%\NewDocumentCommand\creator{ O{} m}
%{
%    \int_incr:N \l_lecturer_int
%    \cs_new_protected:cpn {lecturer\int_use:N\l_lecturer_int}{#2}
%    \tl_if_empty:nTF {#1} {} {\cs_new_protected:cpn {lecturer\int_use:N\l_lecturer_int email}{#1}}
%
%}

%...

% same for \practicer and other
\ExplSyntaxOff

\begin{document}

\creator[]{First}
\creator{Second}
\creator[mail@internet.com]{Third}

\end{document}

• why don't you adapt the names of your commands? skillmon showed you how you should name them and corrected lots of stuff, and you seem to ignored everything. – Ulrike Fischer Dec 5 '20 at 22:29
• You've already been advised that you should not use functions (that is \cs_new...) but token list variables for this purpose. – egreg Dec 5 '20 at 23:02

You're using the wrong approach. To begin with, you shouldn't use functions (aka macros) for storing data, but token list variables or, in this case, sequences.

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\creator}{O{}m}
{
\sk_class_data_add:nnn { creator } { #1 } { #2 }
}
\NewDocumentCommand{\lecturer}{O{}m}
{
\sk_class_data_add:nnn { lecturer } { #1 } { #2 }
}
\NewDocumentCommand{\retrieve}{mm}
{% #1 is the type, creator or lecturer
% #2 is the index
\seq_item:cn { g_sk_class_#1_name_seq } { #2 }
\tl_if_blank:eF { \seq_item:cn { g_sk_class_#1_email_seq } { #2 } }
{ ~ \texttt{\seq_item:cn { g_sk_class_#1_email_seq } { #2 }} }
}

\seq_new:N \g_sk_class_creator_name_seq
\seq_new:N \g_sk_class_creator_email_seq
\seq_new:N \g_sk_class_lecturer_name_seq
\seq_new:N \g_sk_class_lecturer_email_seq

{
% add the name to the proper sequence variable
\seq_gput_right:cn { g_sk_class_#1_name_seq } { #3 }
% add the email to the proper sequence variable
\seq_gput_right:cn { g_sk_class_#1_email_seq } { #2 }
}

\ExplSyntaxOff

\begin{document}

\creator[]{First}
\creator{Second}
\creator[mail@internet.com]{Third}

\lecturer{Me}
\lecturer[]{You}
\lecturer[bela.lugosi@example.com]{Count Dracula}

\retrieve{creator}{3}

\retrieve{lecturer}{2}

\retrieve{lecturer}{3}

\end{document}


• Thank You.It is possible to concatate two sequences (name and email) into comma separated one such name1 (email1), name2, name3 (email3)? – sergiokapone Dec 6 '20 at 8:08
• @sergiokapone The \retrieve` macro was just given as an example. Is your aim to print the list of creators that way? – egreg Dec 6 '20 at 10:24
• My aim both, print comma separated list of creators with email (if it exist), and use creator name by itself in different place. Now I think about creating some subsequent. Thank you. I will try – sergiokapone Dec 6 '20 at 11:22