Here is the boiled-down extract of what I'm trying to do. Apologies beforehand if some of the computations do not make sense, I've modified them for the sake of simplicity.
Basically, I've a function called \basicMacro
which takes an argument, and depending on its value, makes some computations (floating point computations, even if in the simplified example it's not the case).
I want to create another macro (\anotherUseMacro
) which will do some modification to the input variable, and then call the \basicMacro
with an argument.
However, the second step poses problem, and I end up with an empty ()
floating point variable, and I don't know why.
Here is the MWE :
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\fp_new:N \l_cvssAV_fp
\fp_new:N \l_argument_fp
\fp_new:N \l_value_fp
\fp_new:N \l_result_fp
\str_new:N \l_input_str
\NewDocumentCommand \chooseValue { m }{
\str_case:nn {#1}
{
{ N } { 0.85 } % This value will be selected
{ A } { 0.62 } % This will not
}
}
\NewExpandableDocumentCommand \computeValue {m}{
\fp_set:Nn \l_argument_fp { \chooseValue{#1} }
\fp_show:N \l_argument_fp % \l_argument_fp=(). <<<< HERE IS THE ERROR
\fp_set:Nn \l_value_fp { 1 - (1 - \l_argument_fp )}
% 1 - (1 - 0.85 )
}
\NewDocumentCommand \factorScaling {m}{%
\fp_eval:n { 8.22 * (#1) }%
% 8.22 * 0.85
}%
% https://tex.stackexchange.com/a/615358/28926
\NewDocumentCommand \roundup {m}{
\fp_eval:n { ceil(#1,1) }
\fp_compare:nT { ceil(#1,1)=ceil(#1,0) } {.0}
}
\cs_new_protected:Npn \basicMacro #1 {
\computeValue{#1}
% \l_argument_fp=0.85
\fp_set:Nn \l_result_fp { \factorScaling{\chooseValue{#1}} }%
% \l_result_fp=8.22*0.85
% \l_result_fp=6.987
%
\fp_compare:nTF { \l_value_fp <= 0 }
% IF value <=0
{
% value <=0
0.0
}{
\fp_eval:n { round( min( 1.08 * (\l_value_fp + \l_result_fp), 10) ) }%
}%
}
\NewDocumentCommand \anotherUseMacro { m }{%
\str_set:Nn \l_input_str { #1 }
% CALLS basicMACRO
\basicMacro{\l_input_str}
}%
\ExplSyntaxOff
\begin{document}
\basicMacro{N}
\anotherUseMacro{N}
\end{document}
Looking at the logs, I can see that the variable \l_argument_fp
correcly equals 0.85 in the 1st call, but in the second case (when used inside \anotherUseMacro
), it is empty :
l.69 \basicMacro{N}
> \l_argument_fp=().
<recently read> }
Thus, the next operation is invalid, hence the error thrown :
Invalid operation (1)-(())
How can I solve my problem ?
It seems that the expression \fp_set:Nn \l_argument_fp { \chooseValue{#1} }
is not properly executed when it's called from \anotherUserMacro
.
NB : I've little experience with expl3.