LATEX-L Archives

Mailing list for the LaTeX3 project


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
Kelly Smith <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Mon, 28 Jan 2019 06:43:25 +0100
text/plain (73 lines)

While trying to think through some questions about how to best implement
my class, I decided to do some practice with expl3 and write a little
datetime package. (For some reason, regularly switching between a few
projects works better than focusing on just one.)

I should note that I’ve changed my mind about several comments regarding
dates and times that I made several months ago. I mention this because it
pertains to the implementation and my question…

I represent a date with a token list containing a triple:


where each field is an integer expression.

I know that a scan mark “header” is used in the implementation of several
expl3 datatypes but I think that is unnecessary for this because the data
has a single, finite structure and does not require 

Of course, functions that operate on dates need the separate fields: some
sort of extraction function is necessary.

For functions that apply to one date, I use:


where #1 is a function expecting the three integer fields and #2 is the
date variable.

For functions involving two dates, I have:


where #1 is a function expecting the six integer fields and #2 and #3 are
the date variables.

I have discovered that there are several ways to implement the extraction
functions but I am unsure of which is considered best practice. Here I’m
listing three different approaches that I found that work expandably and
don’t use low-level fucntions. Since the one and two date cases are
similar, I’m excluding the one date implementations for brevity.

1. This approach trivial in the one date case but is not much more
   involved in the two date case:

     \cs_new:Nn \__date_extract:NNN
       { \exp_last_unbraced:NNNV \exp_last_unbraced:NV #1 #2 #3 }

2. This approach is extremely general:

     \cs_new:Nn \__date_extract:NNN
       { \exp_last_unbraced:Ne #1 { \exp_not:V #2 \exp_not:V #3 } }

3. This approach, I think, is not quite as clear in its intent:

     \cs_new:Nn \__date_extract:NNN
       { \__date_extract_aux:NVV #1 #2 #3 }

     \cs_new:Nn \__date_extract_aux:Nnn
       { #1 #2 #3 }

     \cs_generate_variant:Nn \__date_extract_aux:Nnn { NVV }

   of course, \exp_args:NNVV could be used directly instead of defining a
   variant here.

Of these, which would be considered the best approach?