3

I guess everything is in the title... But I'll rephrase here. The documentation says:

\seq_new:N -> Creates a new ⟨seq var⟩ or raises an error if the name is already taken. The declaration is global. The ⟨seq var⟩ initially contains no items.

But it also defines:

\l_tmpa_seq -> Scratch sequences for local assignment. These are never used by the kernel code, and so are safe for use with any Latex-defined function. However, they may be overwritten by other non-kernel code and so should only be used for short-term storage.

So what's the point in having a local but global variable? This is the also case for other types.

5
  • 2
    if you do \seq_set:Nn the value is set locally. if you do \seq_gset:Nn it is global. the \l_ or \g_ tells you which is appropriate for this particular variable. so the existence of the variable can be global, even though it is set or changed locally. Commented Sep 22, 2024 at 19:02
  • @cfr: when you write that \l_or \g_l tells you wich is appropriate... do you mean that it's just a convention? I could use \seq_gset:Nn \l_tmpa_seq {A,B,C}? Commented Sep 22, 2024 at 19:24
  • 2
    most of the syntax in expl3 is just a convention. there are some checks and there may be more in the future, but, for the most part it would simply be too expensive to enforce the conventions as the underlying TeX does not make (m)any of these distinctions. so you could (probably) say e.g. \seq_gset_from_clist:Nn \l_foo_bar_tl {A,B,C} and not get an error. the pressure to conform to the conventions laid down by the LaTeX Project is largely social :-). Commented Sep 22, 2024 at 19:45
  • @cfr social and \debug_on:n { all }. Commented Sep 23, 2024 at 7:20
  • 1
    @Skillmon I think the second would be ineffective in the absence of the first even in the case of people who've actually heard of that. (which I certainly have not except very vaguely and extremely recently. certainly I've never used it.) Commented Sep 23, 2024 at 7:35

2 Answers 2

6
\documentclass{article} \pagestyle{empty} \begin{document} \ExplSyntaxOn \seq_new:N \l_pinkfloyd_local_seq \seq_new:N \g_pinkfloyd_global_seq \cs_new_protected:Nn \pinkfloyd_demo: { local : ~ \seq_use:Nn \l_pinkfloyd_local_seq {,} \par global : ~ \seq_use:Nn \g_pinkfloyd_global_seq {,} \par } \seq_set_from_clist:Nn \l_pinkfloyd_local_seq {aardvarks,bonobos,civets} \seq_gset_from_clist:Nn \g_pinkfloyd_global_seq {aardvarks,bonobos,civets} \pinkfloyd_demo: \group_begin: \seq_set_from_clist:Nn \l_pinkfloyd_local_seq {A,B,C,D,E} \seq_gset_from_clist:Nn \g_pinkfloyd_global_seq {W,V,X,Y,Z} \pinkfloyd_demo: \group_end: \pinkfloyd_demo: \ExplSyntaxOff \end{document} 

demo

2
  • Your example is great, even the variable names are well chosen! Commented Sep 22, 2024 at 19:22
  • actually, the example should set the variables inside the group. Commented Sep 23, 2024 at 7:37
7

Variables in expl3 are all declared globally, but may be set either locally or globally. Thus when you do

\seq_new:N \l_my_foo_seq 

the name is reserved globally and set at global scope to an empty sequence. However, this sequence should only be set locally.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.