问题是:expl3
提供seq
变量中用于读取项目的索引位置,有没有办法写入索引位置?我注意到@XZS 在 15 年 7 月 24 日提出的问题太晚了,所以我要求更新在\array
interface3 中添加功能的计划(参见@Christian Hupfer 的评论)
\documentclass{article}
% RN. 24/10/2016
% DESCRIPTION: want to use _seq variable as an "array" data structure and be able
% to not only get (read) but also set (write to) items in indexed positions. Can
% be achieved with "gets" and "puts" or "pops" and "pushes" of course, but this will be
% cumbersome and slow. Worse still, similar holds for tokenlist variables.
\usepackage{xparse}
\ExplSyntaxOn
\seq_new:N \g_rn_Array_seq
\int_new:N \l_rn_Count_int
\int_new:N \l_rn_index_int
\tl_new:N \l_rn_aux_tl
\NewDocumentCommand\myArray{O{1}O{a,b,c,d,e,f,g,h,i,j,k,l,m}}
{
\seq_set_split:Nnn \g_rn_Array_seq {,}{#2}
\int_set:Nn \l_rn_Count_int {\seq_count:N \g_rn_Array_seq}
\tl_set:Nx \l_rn_aux_tl {\seq_item:Nn \g_rn_Array_seq{#1}}
item~#1~in~(\seq_use:Nn \g_rn_Array_seq {,~}) :~\textbf{\l_rn_aux_tl}
}
\ExplSyntaxOff
\begin{document}
1. \verb+\myArray+\\
\myArray
2. \verb+\myArray[6]+\\
\myArray[6]
3. \verb+\myArray[4][a,sdf,qarg,12354m145,rg,ra,h]+\\
\myArray[4][a,sdf,qarg,12354m145,rg,ra,h]
\end{document}\documentclass{minimal}