Skip to content

Instantly share code, notes, and snippets.

@qinglee
qinglee / l3iow.tex
Last active December 10, 2015 23:49
Use a stack to manage the allocation of input and output streams.
\RequirePackage{expl3}
\ExplSyntaxOn
\seq_new:N \c__iow_streams_seq
\seq_new:N \g__iow_streams_seq
\int_step_inline:nnnn \c_zero \c_one \c_fifteen
{ \seq_gput_right:Nn \g__iow_streams_seq {#1} }
\seq_gset_eq:NN \c__iow_streams_seq \g__iow_streams_seq
\tl_new:N \l__iow_stream_tl
@qinglee
qinglee / l3alloc.tex
Created November 5, 2012 06:50
l3alloc: another implementation.
\cs_new_protected:Npn \__alloc_new:nnnN #1#2#3#4
{
\__alloc_setup_type:nnn {#1} {#2} {#3}
\cs_new_protected:cpn { #1 _new:N } ##1 { \__alloc_reg:nNN {#1} #4 ##1 }
}
\cs_new_protected:Npn \__alloc_setup_type:nnn #1#2#3
{
\tl_new:c { g__ #1 _allocation_tl }
\tl_gset:cx { g__ #1 _allocation_tl } { \int_eval:n {#2} }
\tl_const:cx { c__ #1 _allocation_max_tl } { \int_eval:n {#3} }