LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced 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:
Lars Hellström <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Thu, 13 Oct 2011 16:37:51 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (89 lines)
Bruno Le Floch skrev 2011-10-12 18.59:
> On 10/12/11, Joseph Wright<[log in to unmask]>  wrote:
>> One obvious question is how easy would it be to support predicate
>> decision making in such as scheme:
>>
>>    \bool_if:nTF
>>      { \l_my_first_bool&&  ( \l_my_second_bool&&  !\l_my_third_bool ) }
>>
>> which is one of the reasons for the approach currently taken.

My first impulse to a response to that question was "That's a strange 
expression, maybe there's a typo? But as written, I would code that as

   \and:nnnTF{\l_my_first_bool}{\l_my_second_bool}
      {\not:nTF{\l_my_third_bool}}

" But I gather from the subsequent discussion that you're asking about the 
possibilities for using infix notation operations on Church booleans.

> I had the same thought as Joseph. As far as I can tell, the infix
> notation requires us to have unexpandable predicates/booleans (more
> precisely, which stop f-expansion), because those can come in all
> sorts of forms, not necessarily as single tokens. One option would be
>
> \cs_set:Npn \c_true_bool { \exp_stop_f: \use_i:nn }
> \cs_set:Npn \c_false_bool { \exp_stop_f: \use_ii:nn }
> \cs_set:Npn \bool_if:NTF #1 { \tex_romannumeral:D -`q #1 }
>
> That can probably be made to work within boolean expressions, with
> roughly the same efficiency as the current approach. However, it still
> doesn't work for non-expandable tests.

Trivial approach to put a Church boolean into \bool_if:nTF would be to use 
some sort of

   \cs_new:Npn \bool_pred:n #1 {#1 \c_true_bool \c_false_bool}
   % \c_true_bool and \c_false_bool being the current \chardefs.

as follows:

   \bool_if:nTF { \bool_pred:n{\l_my_first_bool} &&
    ( \bool_pred:n{\l_my_second_bool} && !\bool_pred:n{\l_my_third_bool} ) }

Whether whatever scheme you're currently using to parse these expressions 
could be taught to insert the \bool_pred:n (or just \c_true_bool 
\c_false_bool) automatically is of course another matter.

> [1] http://article.gmane.org/gmane.comp.tex.latex.latex3/2187
>
> I think that Lars has in the past [1] advocated against the infix
> syntax as being an attempt to impose upon TeX some foreign and not
> very appropriate syntax (please correct me if I misunderstood you).

Guilty as charged. However, the foreign syntax thing is more of an analytic 
criticism that came at second or third thought. First I had been scared by 
seeing & used for something that had nothing to do with alignments, and 
annoyed by realising that it did not give different priorities to && and || 
(thus seeming to promise a feature that it actually didn't deliver). 
\if_bool:nTF may subsequently have been improved in the latter respect.

> In
> this perspective, providing \and:nn etc. as Lars proposes would be
> much faster than the current approach, and would accomodate trivially
> for non-expandable conditionals.

Another thing about the Church booleans is that they do not require a 
framework to be useable; they can be used directly also in code written with 
\ExplSyntaxOff. I can see that becoming convenient every now and then, for 
document preamble command definitions (even though there arguably has to be 
a leaky abstraction somewhere for them to even become exposed, such things 
will happen).

Along that line of though, I've also toyed with the idea of having an xparse 
o argument return either

     \NoValue       or
     \YesValue{<argument>}

where

\cs_new:Npn \NoValue {-NoValue-}
\cs_new_eq:NN \YesValue \use_i:n
\cs_new:Npn \IfNoValueTF #1 { \use_iii:nnn #1 \use_iii:nnn \use_i:nn }

It's not quite as elegant as the Church booleans, but strikingly simple.


Lars Hellström

ATOM RSS1 RSS2