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:
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Mon, 6 Feb 2012 05:43:00 +0000
Content-Type:
multipart/mixed
Parts/Attachments:
text/plain (5 kB) , recurrence.sty (4 kB) , recurrence.tex (4 kB)
* Bruno Le Floch <[log in to unmask]> [2012-02-05 13:01:41 -0500]:

Hi Bruno,


Thanks again for your comments. I've learned a lot.

I've incorporated most of your changes but some don't work, most are
related to regex. BTW, some of your suggestions in relation to regex
are not documented. For example, \u.

As it stands, the output that's generated by \meaning looks OK, but it
isn't. I don't know enough of plain TeX to know why, but I suspect it
has to do with (regex) substitutions that involve \#1. The following
paragraph explains why.

If you look at the .tex file (I'm attaching .sty and .tex) you will see
that I'm redefining \recurrence_f_2:n in the exact same way as \meaning
suggests it's defined. After this definition \f works flawlessly. Without,
it will fail for any argument greater than 1. I suspect that this is
because the printed #1 may not be correspond to the positional parameter
#1.

At the very end of this email, I'll say a bit more about the substitutions.
The following are some more comments to your previous email.

: (4) As it is, the code will un forever on negative input. You should
: probably use \int_compare_p:n {#1>0} or something like that in the _2
: function.

That's deliberate. I wanted to keep things simple.

: (5) Of course you know it, this code will run exponentially slowly for
: large input. That is difficult to solve (but doable; I can give
: details) if you want an expandable function which expands to the value
: of your recursion. For a non-expandable function of the form
: \recursion_get_value_f:nN { <index> } <int var> (dunno how the
: function should be called), getting a linear-time solution should be
: easier: it involves storing the intermediate results as you get them.

Thanks. I know the solution. As soon as everything works, I want to
provide a flag, which the user can use to tell whether or not to cache
the previously computed values.

: - Naming a function \foo:xx doesn't magically cause expansion of the
: args. You need to define \foo:nn, then \cs_generate_variant:Nn \foo:nn
: { xx }.

Thanks. I now understand. When I'll provide my remaining comments about
the expl3 documentation I'll once more give some comments about that
part of the documentation. I think the documentation is right but it's
not clear for somebody who is new to the matter. (Or for that sake,
somebody like me who doesn't know enough low-level TeX. It would be
nicer if the documentation could be explained without reference to TeX.
I think it should be possible.)

: - Variables should be renamed to indicate whether they are local or
: global, and in the team we always put the variable's type (tl,
: int,...) at the end.

Thanks.

: [ snip ]

: \cs_new_nopar:Npn \recurrence_define_constant:xx #1#2{%
:     \edef\recurrence_current_case_count{\int_use:N \recurrence_case_count}
:     % Shudder.
:     % => \int_set_eq:NN \l_recurrence_current_case_int \l_recurrence_case_int
:     % (of course, you'll need \int_new:N \l_recurrence_current_case_int before)
:     \int_incr:N \recurrence_case_count
:     \cs_new_nopar:cpx {\recurrence_case_name:n
: \recurrence_current_case_count} ##1{
:         \exp_not:N
:         \int_compare:nTF {##1=#1} {#2}
:                          {\cs:w \recurrence_case_name:N \recurrence_case_count
:                           \cs_end:{##1}}
:     }
: }
: % - If you use \int_eval:n in the previous function, you can drop the
: % recurrence_current_case variable completely, and use
: %   \recurrence_case_name:n { \l_recurrence_case_int + 1 }

That doesn't work. If I use

    \cs_new_nopar:cpx {\recurrence_case_name:n {\l_recurrence_case_count_int - 1}} ##1{

I get a run time error, even for f{0}. I haven't had the time to look into it but
I'll do it when everything else works. (Saving the variable is my least concern.)

: % #1 is name
: % #2 is index
: % #3 is tl list
: \cs_new_nopar:Npn \recurrence_sanitise:nnN #1#2#3{
:     \regex_replace_all:nnN {#2} {\#1} #3 % This \# looks very odd.
: Perhaps "\cP\#" ?
:     \regex_replace_all:nnN {\b#1\b\[([^\]]+)\]} {\\#1:n\{\1\}} #3
: }

I've now changed this to:

% #1 is name
% #2 is index
% #3 is tl list
\cs_new_nopar:Npn \recurrence_sanitise:nnN #1#2#3{
    \regex_replace_all:nnN {#2} {\#1} #3
    \regex_replace_all:nnN {\b#1\[([^\]]+)\]} {\\#1:n \cB\{\1 \cE\}} #3
}
\cs_generate_variant:Nn \recurrence_sanitise:nnN {VV}

\cP\# doesn't work. I get the following error:

    Illegal parameter number in definition of \regex_replacement_tl:n.

: % The second \b does nothing. Including #1 directly is risky if it
: % contains special characters that should be escaped. Instead,
: % you should try " \u{l_recurrence_name_tl} " (or whatever tl var
: % contains that #1).

l_recurrence_name_tl is indeed the one. I tried \u{l_recurrence_name_tl}
but then the substitution didn't work at all.

: % \\#1:n\{\1\}
: % => \c{\u{l_recurrence_name_tl}:n} \cB\{ \1 \cE\}
: % What does this do? Well, \c{...} is like the c-type argument
: % (think \exp_not:c). \u{...} is like the v-type argument, and
: % unpacks the variable \l_recurrence_name_tl, so that's similar
: % to your \\#1:n, except that it produces an actual control sequence
: % instead of a string of characters with catcode other.

I tried \c{\u{l_recurrence_name_tl}:n} as well but again, the substitution
didn't work at all.

: [ snip ]

Thanks!

Regards,


Marc


ATOM RSS1 RSS2