0

I want the ability to reset the values of adr_keys to blank values. What type of function should I construct?

I will be using

\tl_if_blank:VF \l_dwlg_tl
  { \tl_use:N \l_dwlg_tl \\ }

to print the values by checking whether values are blank.

The problem with using initial is that this would only apply on the first instance. And using default would require me to supply the name and keeping it empty.

The command \adrPrint would print the key values. For the second call to \adrPrint I want to use the values used in the previous \adrPrint. But I need to reset all values for the third call to \adrPrint

\documentclass[a4paper,12pt]{article}

\ExplSyntaxOn

\keys_define:nn { adr_keys } { name .tl_set:N = \l_name_tl, role .tl_set:N = \l_role_tl, kmpn .tl_set:N = \l_kmpn_tl, dwlg .tl_set:N = \l_dwlg_tl, hmlt .tl_set:N = \l_hmlt_tl, vltw .tl_set:N = \l_vltw_tl, cbrg .tl_set:N = \l_cbrg_tl, knty .tl_set:N = \l_knty_tl, pstc .tl_set:N = \l_pstc_tl, ktry .tl_set:N = \l_ktry_tl, }

\ExplSyntaxOn

\begin{document}

\adrPrint { name={Heime Borgia}, dwlg={405 Hilgard Ave}, cbrg={Los Angeles}, knty={California}, pstc={90095}, ktry={United States}, }

\adrPrint { name={Likku Cirillu}, dwlg={409 Hilgard Ave}, }

\adrReset

\adrPrint { name={Heime Borgia}, dwlg={Gower Street}, cbrg={London}, pstc={WC1E 6BT}, }

\end{document}

Ragonese
  • 171
  • 4
  • 1
    If you set them locally, you don't need to reset them. If that's not possible for some reason, you just set them equal to the constant empty token list (either using keys or directly). By the way, you have two \ExplSyntaxOn. – cfr Mar 11 '24 at 02:17
  • 2
    Off-topic: Your variables aren't named correctly. They should include the module name to avoid conflicts e.g. not \l_name_tl (which is obviously highly likely to conflict with all kinds of stuff) but \l_adr_keys_name_tl etc. The same is true of any functions you define. – cfr Mar 11 '24 at 02:20
  • 1
    You already asked the question in the one marked as duplicate. There you wanted some value, but “empty” is a possible value, so the solution is exactly the same. – egreg Mar 11 '24 at 09:23
  • That would require me to supply the name to default it, which I want to avoid. – Ragonese Mar 11 '24 at 10:30
  • @Ragonese I am not sure what you mean: if you want to reset to 'some value', either you use grouping or you supply the reset value. – Joseph Wright Mar 11 '24 at 10:39
  • Sometimes I want to use the existing values except the ones specified as arguments. At other times I want to reset all values to empty before specifying the arguments in the print call. – Ragonese Mar 11 '24 at 10:54

1 Answers1

2

Easiest would be to use key pre-setting to create a token list which contains the correct instructions:

\keys_precompile:nnN { adr_keys }
  {
    name = ,
    role = ,
    kmpn = ,
    dwlg = ,
    hmlt = ,
    vltw = ,
    cbrg = ,
    knty = ,
    pstc = ,
    ktry = ,
  } \l_tmpa_tl
\cs_new_protected:Npe \adr_reset_keys:
  { \exp_not:V \l_tmpa_tl }

I've chosen to put the instructions into a command: that is a matter of taste (as fundamentally a function with no arguments and a token list are basically the same thing).

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • In interface3 the description of \exp_not:V command is that \exp_not:V variable recovers the content of the variable, then prevents expansion of this material in x-type or e-type arguments using \exp_not:n. Would this reapply the commands in \l_tmpa_tl to adr_keys ? – Ragonese Mar 11 '24 at 09:44
  • The reason for using \exp_not:V here is that we have a token list containing a set of reset instructions, but conceptually this would read better as a function with no arguments (to me at least). So I'm, getting the contents of the token list and 'transferring' them - this is about sticking to the official interfaces. You could choose to simply save into a private token list and insert that: the result is the same. (Use \tl_show:N to see what is being constructed.) – Joseph Wright Mar 11 '24 at 10:39
  • I get an Undefined control sequence. l.314 \keys_precompile:nn { adr_keys }. Have made a user command to reset the values with \NewDocumentCommand {\AdrRst} { } { \adr_reset_keys: } that a user can call. – Ragonese Mar 11 '24 at 11:03
  • @Ragonese Sorry, that's a typo: I'll correct – Joseph Wright Mar 11 '24 at 11:39
  • The complaint Undefined control sequence. l.335 \cs_new_protected:Npe \adr_reset_keys: is shown after your correction. – Ragonese Mar 11 '24 at 11:58
  • @Ragonese Sounds like you might have an older expl3 installation: try \cs_new_protected:Npx instead – Joseph Wright Mar 11 '24 at 11:59
  • I have this This is LuaHBTeX, Version 1.15.0 (TeX Live 2022) restricted system commands enabled. (./health.ltx LaTeX2e <2022-06-01> patch level 5 L3 programming layer <2022-09-28>. – Ragonese Mar 11 '24 at 12:54
  • @Ragonese Yes, that's quite a while ago - so you'll need \cs_new_protected:Npx. – Joseph Wright Mar 11 '24 at 13:11
  • I will update my Tex Live instead. – Ragonese Mar 11 '24 at 13:23
  • Would you really use \l_tmpa_tl or is that just for the example? – cfr Mar 12 '24 at 03:48
  • @cfr Just an example: I'd use a private scratch tl – Joseph Wright Mar 12 '24 at 06:31