LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Classic View

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

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

Print Reply
Will Robertson <[log in to unmask]>
Thu, 12 Feb 2009 17:38:17 +1030
text/plain (1725 bytes) , smime.p7s (2446 bytes)
On 12/02/2009, at 5:00 PM, Will Robertson wrote:

> Having some more troubles, this time with \token_if_expandable.  
> Unfortunately, the only token I can find that trips this "true" is  
> \relax or \scan_stop:, which isn't exactly what I thought the  
> intended behaviour was supposed to be.

After searching through c.t.t. for a while, I found an insane thread  
talking about this sort of thing:

Dan Luecking's comment is that
"seems a feasible test for expandability of a token".

I'm in a rush, and might be barking up the wrong tree here, but here's  
a re-implementation of \token_if_expandable that *seems* to behave in  
a more coherent manner.

The big kicker is that it only returns true for tokens that will  
expand into something else -- regardless of whether they are able to  
be fully expanded or not. And really, who could expect anything more?


\def:Npn \token_if_expandable_p:N #1{
   \cs_if_exist:NTF #1 {
     \exp_after:NN \if_token_eq:NN \exp_not:N #1 #1
       \c_false \else: \c_true \fi:
   } {\c_false}
\def_test_function:npn {token_if_expandable:N} #1{
\token_if_expandable:NTF \FOOOO {T}{F}
\token_if_expandable:NTF a {T}{F}
\token_if_expandable:NTF \foo {T}{F}
\token_if_expandable:NTF \the {T}{F}
\expandafter\ifx\noexpand\foo\relax T\else F\fi
\expandafter\ifx\noexpand\the\relax T\else F\fi
\expandafter\ifx\noexpand\FOOO\relax T\else F\fi
\catcode`\z=13 \def z{\write18{ls}}
\expandafter\ifx\noexpand z\relax T\else F\fi
\expandafter\ifx\noexpand aa T\else F\fi
\expandafter\ifx\noexpand\message\message T\else F\fi
\expandafter\ifx\noexpand\write\write T\else F\fi