7

When reading the thread about low-level arrays in TeX I stumbled over a note in Bruno Le Floch's answer:

A long string of characters is stored more efficiently as a csname than as a list of tokens. This has been used at some point in l3fp, storing 10000 decimals of 1/(2pi) as \159154943091895..., to be passed to \string when needed.

I can't find that definition in the l3fp files and I'm curious how it works. The problem seems to boil down to the question "How do you refer to a control sequence name without knowing the full name?" For example, if you assign a shorter name \expandafter\let\expandafter\short\csname very long name\endcsname, you can't refer to the original name with \short later because only the meaning is assigned to \short. On the other hand, a construction that involves \def or similar pretty much defeats the purpose because then you need to store the characters as tokens again.

What is the (plain TeX/e-TeX) pattern used here that makes this efficient string storing work?

  • 2
    It used to be that way in l3fp, but now the same is achieved with \intarray which is even more efficient (it uses \fontdimen). – egreg Sep 4 '18 at 22:20
  • From the section of l3fp-trig.dtx where this is done (with a new method, as egreg said): "The memory footprint (1/2 byte per digit) is the same as an earlier method of storing the data as a control sequence name, but the major advantage is that we can unpack specific subsets of the digits without unpacking the 10112 decimals." – Phelype Oleinik Sep 4 '18 at 22:29
  • 1
    I don't see why you say you need to store the character tokens if using a macro \edef\zzz{\expandafter\noexpand\csname 1234567890\endcsname} is equivalent (if you set catcodes up) to \def\zzz{\1234567890} and stores the 10 digit number as a single csname, which you can get back the digits via \meaning\zzz – David Carlisle Sep 5 '18 at 0:20
2

After

\edef\zzz{\expandafter\noexpand\csname 1234567890\endcsname} 

The 10 digit number is stored as a single csname, as the definition is equivalent (if you set catcodes up) to

\def\zzz{\1234567890}

The number can be retrieved by \meaning\zzz or \expandafter\string\zzz and stripping the respective prefix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.