4

From the documentation I know that \tl_use:N and \str_use:N are optional. Those variables can be used directly. Isn’t that true for even more types?

Is it likely that more \xx_new:N will be officially raised to that optional level as well (i.e. if overwriting is not an issue, intention of use need not be declared and \xx_set:Nn can be called directly)? (like with \cs_set:Nn)

Especially in the light of local variables.—I’m not going to start a habit of using \l_tmpa_tl instead of descriptive variable names (which I consider error-prone), so I’ll have a bunch of \tl_new:N hanging out of functions.

  • L3 can't change the fundamentals of the underlying Tex system. Macros can be used directly but counts boxes and other register types require a prefix accesor function – David Carlisle Oct 21 '19 at 17:41
  • Depends on exactly what you mean, as @DavidCarlisle says. For example, a prop is currently a macro with certain content even when 'empty'. But your will (probably) get away with various operations even if you don't declare it first. – Joseph Wright Oct 21 '19 at 17:56
  • Note that if you or someone else activates checking, then you have to have declarations to avoid errors – Joseph Wright Oct 21 '19 at 17:56
  • As TeX scope is not based on macros but on explicit groups, you can never have a situation where some 'local variables' are just 'inside a macro' unless it has a group anyway. As I've said elsewhere, in the end it fits better into how TeX works just to declare variables globally even if they are used local-to-a-group. – Joseph Wright Oct 21 '19 at 19:05
8

Using just \l_siemer_foo_tl or \l_siemer_foo_str instead of

\tl_use:N \l_siemer_foo_tl
\str_use:N \l_siemer_foo_str

is indeed allowed, but not really recommended. I generally try to prefix with \tl_use:N (or \str_use:N because it's cleaner programming, unless conciseness makes the “unprefixed” way preferable. Note that \tl_use:N requires a few expansion steps, whereas the unprefixed form only requires one and this can make a difference in an already long program.

On the other hand, \tl_use:N also checks whether the following variable is declared, when the check-declarations option is in force.

There are other <module>_use:N functions, namely \dim_use:N, \skip_use:N, \muskip_use:N, \int_use:N, \box_use:N and \fp_use:N; omitting these will lead to disasters.

Using any variable (except tl or str, as mentioned) in the wild will do nothing good; in some cases you get a sensible error, such as A sequence was misused. or A floating point with value '1.2' was misused. In other cases (think to dim variables) you'd get a very low level error message or unexpected output.

The only other variable type that could be used in the wild is clist, but this is just for reasons of implementation and this feature should not be relied upon. Thus \l_siemer_foo_clist should not be considered as a shorthand for \clist_use:Nn \l_siemer_foo_clist {,} (which I don't really see a use for anyway). Your nice program using it might no longer work because the internal implementation of clist variables has changed.

For other variable types there is no <module>_use:N function, but other arguments are needed that exploit the variable's internal structure.

And, no, <module>_new:N is definitely not optional, for any variable type.

6

Any variable type that is ultimately a macro can be 'used' without an accessor. However, that might lead to surprising results: for example, take a look at the raw structure of an fp!

The official position on declaration of variables will not change: they have to be declared before use. The one exception is where they are 'auto-created' by l3keys: a compromise to avoid extremely repetitive code.

  • ...the only variable types which are officially allowed to be used without accessor function are tl and str. You have any other types in mind which would fit into this category as well? – Robert Siemer Oct 21 '19 at 19:07
  • @RobertSiemer Everything else has some internal structure, though a clist is really just a very restricted tl. – Joseph Wright Oct 21 '19 at 19:16
  • So is it okay to use clists without accessor in practice? Which should be updated: the documentation or code which uses clists without accessor? – Robert Siemer Oct 21 '19 at 19:41
  • @RobertSiemer I'm not sure what use you'd make of \l_tmpa_clist out in the wild; note that we have \clist_use:Nn and \clist_use:Nnnn, but no \clist_use:N. – egreg Oct 21 '19 at 19:44
  • ...as a shortcut for \clist_use:Nn \l_tmpa_clist {,} – Robert Siemer Oct 21 '19 at 19:46

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.