LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Michiel Helvensteijn <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Fri, 12 Jul 2013 15:49:19 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (75 lines)
Hello all,

I have found it useful in my recent work to have unique csnames
generated automatically.

For example, when implementing a `\something_map_inline:Nn` from an
existing `\something_map_function:NN`, there is the need to
automatically generate a function from the provided loop body. It is
not possible to keep using the same control sequence over and over,
because that would make it impossible to do any nesting.

I am thinking about argument specifiers:

:U  and  :u

Their actual parameters are a variable and variable-name respectively,
which will contain the uniquely generated csname. The formal parameter
in both cases is the uniquely generated control sequence (the cs, not
the csname; same as with :N and :c).

Here's an example of its use:

\tl_new:N \l__something_map_csname_tl
\cs_new_protected:Nn \something_map_inline:Nn {
    \cs_set:Upn \l__something_map_csname_tl ##1##2 {#2}
    \something_map_function:Nc #1 \l__something_map_csname_tl
}

Internally, I suspect it'll be easy enough to generate unique csnames.
In my 'with' package (not in CTAN yet) I do it simply by increasing a
counter (https://code.google.com/p/latex-with/source/browse/trunk/with.sty).

Obviously any function with a :U or :u argument is protected (as with :x).

--- --- --- ---

I now go one step further. The following idea is related to the above,
but please evaluate them separately.

It's about a third argument specifier that would go a long way towards
solving the problem stated in
[http://tex.stackexchange.com/questions/101833/latex3-how-to-get-reliable-control-over-the-level-of-expansion].

Briefly, there is need for a simple and generally applicable technique
to store user-supplied data and move it around ówith the guarantee
that it is never expanded or modifiedó and then to return (pass as a
parameter; leave in the input stream) said data exactly as it was
received.

Of course, there are already many ways to accomplish this, but they
are always dependent on the situation (i.e. ad-hoc) and error-prone.

I suggest another new argument specifier:

:r

The actual parameter is any kind of token-list (the 'user-supplied
data'). The formal parameter is a uniquely generated csname to a macro
containing that token-list: a "pointer" or "reference".

Because of this extra level of redirection the pointer can be stored,
moved around, expanded and dragged through the mud with relative
certainty that the original data remains intact. The corresponding
"dereference" specifiers already exist:

:v  and  :c

The first yields the data exactly as it was stored. The second yields
a control sequence through which the data can be modified.

Let me know what you think.

--
www.mhelvens.net

ATOM RSS1 RSS2