I often need to define macros whose name contains the value of a counter, notably to attribute a value to multiple objects: in python I would do:
myArray[0] = "mystyle"
Unfortunately, I can't use \expandafter\xdef\csname myArray\the\mycounter\endcsname because in LaTeX, it is not possible to have numbers in macros. For now I'm using \roman{mycounter} instead, but it feels very hacky as it can take a long time to computer the roman version of a number... Is there any better solution? I tried notably to check if LaTeX3 provided something better for this kind of associative arrays containing numbers, but I can only find integers arrays (I guess integers that can only contain arrays). The other option I imagine is maybe a sequence of tupples, but then the access time is linear which is not very efficient.
MWE
\documentclass[options]{article}
\begin{document}
\newcounter{mycounter}
\expandafter\edef\csname myArray\roman{mycounter}\endcsname{Hello}
Bonjour'' is\csname myArray\roman{mycounter}\endcsname''.
\end{document}

\roman{mycounter}with\themycounter(or\arabic{mycounter}) – David Carlisle Feb 02 '22 at 23:56\expandafter\xdef\csname myArray\the\mycounter\endcsnameif\mycounterwas defined (eg by\newcount\mycounter) your code shown doesn't define it – David Carlisle Feb 03 '22 at 00:01\csname foo17$_B\endcsname's replacement text is the control-word-token\foo17$_B. Expandable tokens, e.g.\the\mycounter, between\csnameand\endcsnameare expanded. In expl3-syntax you can use\use:cinstead of\csname..\endcsname. You might be interested in What exactly do \csname and \endcsname do? – Ulrich Diez Feb 03 '22 at 02:30\catcode\1=11you could use\def\zz11{abc}and use\zz11but if you restore the catcode of 1 you would need csname again as\zz11would parse as\zz 1 1` the restriction about digits is not a restriction on allowed names, it is just a feature of how input characters are parsed into tokens – David Carlisle Feb 03 '22 at 07:31\csname..\endcsnamewhen tokenization of .tex-input is already done. – Ulrich Diez Feb 03 '22 at 12:42