expl3 provides predicates to test whether variables of various data types exist, e.g. \cs_if_exist:NTF, \tl_if_exist:NTF, \str_if_exist:NTF, \int_if_exist:NTF, etc. However, I couldn't find a similar function for the data type token (Part XV in the Interfaces3 documentation). So How can I test whether a token variable exists (for instance, one that was possibly created using \token_new:Nn)?
Here's a use case. Whenever I write LaTeX3 functions that take parameters, first thing I do inside the function's body is name the parameters, i.e. I initialize local variable with the raw parameters #1, #2. After this point I never use the raw parameters again; only the named variables.
So suppose I wish to write a function, \g, that takes a single argument that should be of type "function variable" that may or may not be defined, and then I wish to test whether this variable is defined. So \g's structure would be something like this:
\ExplSyntaxOn
\cs_new:Npn \g #1
{
\token_new:Nn \f {#1}
\token_if_exist:NTF \f {...} {...}
}
\ExplSyntaxOff
Except \token_if_exist:NTF is not available from expl3.
tokenis for (I guess there\cs_set_eq:NNand\cs_if_exist:NTFis the logical answer), but I'm not capable of answering with security. In any case, I remember that you have been told that the declarations_new:should not be inside of a function; and I see that you keep writing_new:statements inside of functions, why? – Manuel Oct 17 '17 at 08:19\token_new:Nnis mainly for saving 'copies' of character tokens. It therefore doesn't have unique 'place' to put tokens. I'm not sure how the result of your proposed\token_if_exist:N(TF)differs from\cs_if_exist:N(TF), other than that presumably the former should allow character tokens. – Joseph Wright Oct 17 '17 at 08:24\cs...functions is that I cannot assign to a variable of typecsan argument that is a control sequence that may not be defined. So in the above example, I couldn't make\fa variable of typecs. – Evan Aad Oct 17 '17 at 08:30expl3' comments to chat: I've retained those that seem directly focussed on the question. – Joseph Wright Oct 17 '17 at 08:42\cs_set_eq:NN \f \whateverundefined? – Manuel Oct 17 '17 at 08:48tokenfunctions are somewhat 'under-reviewed' compared to other parts of the code: several of them are 'cool ideas' or similar that may not fit that well with the longer-term aims of the team. – Joseph Wright Oct 17 '17 at 09:12