[latex3-commits] [git/LaTeX3-latex3-latex3] main: Cleaner approach to var creation (0004eccc8)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed May 25 15:32:13 CEST 2022


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/0004eccc885858d5ab59aedb857a5a3159b62fd7

>---------------------------------------------------------------

commit 0004eccc885858d5ab59aedb857a5a3159b62fd7
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed May 25 14:32:13 2022 +0100

    Cleaner approach to var creation


>---------------------------------------------------------------

0004eccc885858d5ab59aedb857a5a3159b62fd7
 l3packages/xtemplate/xtemplate.dtx | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/l3packages/xtemplate/xtemplate.dtx b/l3packages/xtemplate/xtemplate.dtx
index e550aca02..6f36c3dea 100644
--- a/l3packages/xtemplate/xtemplate.dtx
+++ b/l3packages/xtemplate/xtemplate.dtx
@@ -1617,6 +1617,13 @@
             \prop_put:Non \l_@@_vars_prop
               \l_@@_key_name_tl {#1#2}
           }
+        { function }
+          {
+            \cs_if_exist:NF #2
+              { \cs_new:Npn #2 { } }
+            \prop_put:Non \l_@@_vars_prop
+              \l_@@_key_name_tl {#1#2}
+          }
         { instance }
           {
             \prop_put:Non \l_@@_vars_prop
@@ -1627,7 +1634,7 @@
         \tl_if_single:nTF {#2}
           {
             \cs_if_exist:NF #2
-              { \@@_create_variable:N #2 }
+              { \use:c { \@@_map_var_type: _new:N } #2 }
             \prop_put:Non \l_@@_vars_prop
               \l_@@_key_name_tl {#1#2}
           }
@@ -1639,24 +1646,20 @@
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}{\@@_create_variable:N}
-%   A shortcut to create non-declared variables. Some types need a name
-%   mapping, others can be used directly.
+% \begin{macro}{\@@_map_var_type:}
+%   Turn a \enquote{friendly} variable type into an \texttt{expl3} one.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_create_variable:N #1
+\cs_new_protected:Npn \@@_map_var_type:
   {
-    \str_case:onF \l_@@_keytype_tl
+    \str_case:on \l_@@_keytype_tl
       {
-        { boolean }   { \bool_new:N #1 }
-        { commalist } { \clist_new:N #1 }
-        { function }  { \cs_new:Npn #1 { } }
-        { instance }  { \cs_new_protected:Npn #1 { } }
-        { integer }   { \int_new:N #1 }
-        { length }    { \dim_new:N #1 }
-        { real }      { \fp_new:N #1 }
-        { tokenlist } { \tl_new:N #1 }
+        { boolean }   { bool }
+        { commalist } { clist }
+        { integer }   { int }
+        { length }    { dim }
+        { real }      { fp }
+        { tokenlist } { tl }
       }
-      { \use:c { \l_@@_keytype_tl _ new:N } #1 }
   }
 %    \end{macrocode}
 % \end{macro}





More information about the latex3-commits mailing list.