## 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 >>]

 Subject: Re: The nature of popping from an empty sequence From: Frank Mittelbach <[log in to unmask]> Reply To: Mailing list for the LaTeX3 project <[log in to unmask]> Date: Thu, 14 Apr 2011 17:22:15 +0200 Content-Type: text/plain Parts/Attachments: text/plain (62 lines)
Will Robertson writes:
> On 14/04/2011, at 1:14 AM, Joseph Wright wrote:
>
> > Currently, if you do
> >
> >  \prop_get:NnN \<prop-list> { <key> } \<tl var>
> >
> > and the <key> is not in the \<prop-list> then the \<tl var> ends up as
> > \q_no_value. On the other hand, for sequences trying to 'pop' or 'get'
> > from an empty sequence leads to a (deliberate) error.
>
>
> My personal thoughts:
>
> * These should probably be consistent.

yes. if we change the interface then we should do that consistently on all
similar functions.

> * I think returning a quark is dangerous in case of sloppy package authors.

this is a danger, and given that you need to always do a test to ensure that
you do not run into this trap we may actually provide the test (ie change the
interface).

> * I favour a deliberate error message for all in such cases, with a variant
> * function for the "error" case; e.g.,
>
>     \seq_clear:N \l_tmp_seq
>     \seq_pop:NN \l_tmp_seq \x
>
> should yield "Error: The sequence \l_tmp_seq is empty." with the possibility of also writing

But I'm not sure that the above function is actually of much use. When could
you actually use it? Only if you always know (or think you know) that your
sequence is non-empty at the time of the call. Otherwise you would need to
use the other function (or in the current system you would need to test after
the get).

>     \seq_clear:N \l_tmp_seq
>     \seq_pop:NNF \l_tmp_seq \x { <recovery code> }
>
> in which the recovery code is executed in this case.

All in all I think the core functions to switch to are in fact those that get
an addition "F" argument? Then the test is being done for
you always but you can control its actions.

In addition we could provide a predefined error command that you could
stick into the F argument

\seq_empty_err:N

ok ok, that effectively means

\cs_new:Npn \seq_pop:NN #1#2 { \seq_pop:NNF #1 #2 {\seq_empty_err:N #2} }

in which case we might as well provide that ... :-)

frank