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}
6
  • 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 at 2: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 at 2: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 at 9:23
  • That would require me to supply the name to default it, which I want to avoid.
    – Veak
    Mar 11 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 at 10:39

1 Answer 1

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).

11
  • 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 ?
    – Veak
    Mar 11 at 9: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 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.
    – Veak
    Mar 11 at 11:03
  • @Ragonese Sorry, that's a typo: I'll correct
    – Joseph Wright
    Mar 11 at 11:39
  • The complaint Undefined control sequence. l.335 \cs_new_protected:Npe \adr_reset_keys: is shown after your correction.
    – Veak
    Mar 11 at 11:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .