Why appending box dimensions to a sequence (in a loop) makes that sequence only contain duplicates of last dimension?How to adjust default horizontal and vertical space such that it meets following requirements (related to parshape, custom list and picture spacing)?Why are box dimension assignments both local and global?Making a fake figure that holds a text box of specified dimensionsWhy does adjust box not resize to the dimensions givenocgx2, xparse, expl3: splitting comma separated OCMD/OCGs lists of arguments for references automation

Use GPLv3 library in a closed system (no software distribution)

Does code obfuscation give any measurable security benefit?

What would a chair for a Human with a Tail look like?

To project, or not to project? Extracting raster values with R

I don't want my ls command in my script to print results on screen

Can elves trance in armor without any downsides?

Use of tidyeval based non-standard evaluation in recode in right-hand side of mutate

Linux Commands in Python

Meaning of “Bulldog drooled courses through his jowls”

What is the white square near the viewfinder of the Fujica GW690?

Why it is a big deal whether or not Adam Schiff talked to the whistleblower?

How would a race of humanoids with tails design [vehicle] seats?

How to pronounce correctly [b] and [p]? As well [t]/[d] and [k]/[g]

How to deal with people whose priority is to not get blamed?

What exactly is meant by "partial function" in functional programming?

What's the meaning of Electrical Inches?

Why do baby boomers have to sell 5% of their retirement accounts by the end of the year?

Why is lambda return type not checked at compile time

Should I respond to a sabotage accusation e-mail at work?

How to cut a perfect shape out of 4cm oak?

How were Kurds involved (or not) in the invasion of Normandy?

Solve command does not solve this equation!

Confronted about an Amazon review

Making a pikuach nefesh phone call on Yom Kippur - mitsva or something to be avoided?



Why appending box dimensions to a sequence (in a loop) makes that sequence only contain duplicates of last dimension?


How to adjust default horizontal and vertical space such that it meets following requirements (related to parshape, custom list and picture spacing)?Why are box dimension assignments both local and global?Making a fake figure that holds a text box of specified dimensionsWhy does adjust box not resize to the dimensions givenocgx2, xparse, expl3: splitting comma separated OCMD/OCGs lists of arguments for references automation






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









4

















Loop steps from 1 through 9. Each step puts current index digit of the loop into a box and extracts the digit's width. The width is then appended as dimension value to a sequence. Although the sequence contains 9 values at the end, oddly all of them are dimension (width) of digit 9. All values of the sequence are overwritten to new dimension at each step. Maybe you can figure out the core of the problem.



documentclass[varwidth=100mm]standalone
usepackageexpl3
usepackagefontspec
setmainfontImpact
begindocument
ExplSyntaxOn

seq_new:NmySeq
box_new:NmyBox
int_step_inline:nn9
hbox_set:NnmyBox#1
% display dimension before adding it to sequence
#1=dim_eval:nbox_wd:NmyBox\ % output
% add dimension to sequence
seq_put_right:NnmySeq
dim_eval:nbox_wd:NmyBox
% display current contents of the sequence
seq_use:NnmySeq_\\

% display all dimensions (contains only duplicates of last dimension)
seq_use:NnmySeq,~

ExplSyntaxOff
enddocument











share|improve this question


































    4

















    Loop steps from 1 through 9. Each step puts current index digit of the loop into a box and extracts the digit's width. The width is then appended as dimension value to a sequence. Although the sequence contains 9 values at the end, oddly all of them are dimension (width) of digit 9. All values of the sequence are overwritten to new dimension at each step. Maybe you can figure out the core of the problem.



    documentclass[varwidth=100mm]standalone
    usepackageexpl3
    usepackagefontspec
    setmainfontImpact
    begindocument
    ExplSyntaxOn

    seq_new:NmySeq
    box_new:NmyBox
    int_step_inline:nn9
    hbox_set:NnmyBox#1
    % display dimension before adding it to sequence
    #1=dim_eval:nbox_wd:NmyBox\ % output
    % add dimension to sequence
    seq_put_right:NnmySeq
    dim_eval:nbox_wd:NmyBox
    % display current contents of the sequence
    seq_use:NnmySeq_\\

    % display all dimensions (contains only duplicates of last dimension)
    seq_use:NnmySeq,~

    ExplSyntaxOff
    enddocument











    share|improve this question






























      4












      4








      4








      Loop steps from 1 through 9. Each step puts current index digit of the loop into a box and extracts the digit's width. The width is then appended as dimension value to a sequence. Although the sequence contains 9 values at the end, oddly all of them are dimension (width) of digit 9. All values of the sequence are overwritten to new dimension at each step. Maybe you can figure out the core of the problem.



      documentclass[varwidth=100mm]standalone
      usepackageexpl3
      usepackagefontspec
      setmainfontImpact
      begindocument
      ExplSyntaxOn

      seq_new:NmySeq
      box_new:NmyBox
      int_step_inline:nn9
      hbox_set:NnmyBox#1
      % display dimension before adding it to sequence
      #1=dim_eval:nbox_wd:NmyBox\ % output
      % add dimension to sequence
      seq_put_right:NnmySeq
      dim_eval:nbox_wd:NmyBox
      % display current contents of the sequence
      seq_use:NnmySeq_\\

      % display all dimensions (contains only duplicates of last dimension)
      seq_use:NnmySeq,~

      ExplSyntaxOff
      enddocument











      share|improve this question

















      Loop steps from 1 through 9. Each step puts current index digit of the loop into a box and extracts the digit's width. The width is then appended as dimension value to a sequence. Although the sequence contains 9 values at the end, oddly all of them are dimension (width) of digit 9. All values of the sequence are overwritten to new dimension at each step. Maybe you can figure out the core of the problem.



      documentclass[varwidth=100mm]standalone
      usepackageexpl3
      usepackagefontspec
      setmainfontImpact
      begindocument
      ExplSyntaxOn

      seq_new:NmySeq
      box_new:NmyBox
      int_step_inline:nn9
      hbox_set:NnmyBox#1
      % display dimension before adding it to sequence
      #1=dim_eval:nbox_wd:NmyBox\ % output
      % add dimension to sequence
      seq_put_right:NnmySeq
      dim_eval:nbox_wd:NmyBox
      % display current contents of the sequence
      seq_use:NnmySeq_\\

      % display all dimensions (contains only duplicates of last dimension)
      seq_use:NnmySeq,~

      ExplSyntaxOff
      enddocument








      boxes expl3 latex3 dimensions






      share|improve this question
















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 26 at 5:58







      bp2017

















      asked May 26 at 4:39









      bp2017bp2017

      1,5654 silver badges19 bronze badges




      1,5654 silver badges19 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          4


















          You need to expand the value: use



          seq_put_right:Nx


          instead.



          What's the problem? If you do



          hbox_set:Nn l_tmpa_box A 
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box
          hbox_set:Nn l_tmpa_box AA
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box


          this results in the sequence to contain the following items (without the outer braces, as it would be displayed by seq_show:N l_tmpa_seq)



           dim_eval:n box_wd:N l_tmpa_box 
          dim_eval:n box_wd:N l_tmpa_box


          When the sequence is used, the width of the current contents of l_tmpa_box is employed: the value it had at the moment of assignment has never been mentioned.



          With seq_put_right:Nx you instead get the value frozen at the moment of the assignment.



          Would it be “better” to use



          exp_args:NNx seq_put_right:Nn l_tmpa_tl ...


          No. Using (or defining, in case of need) a variant is better style.






          share|improve this answer























          • 1





            @bp2017 In my opinion it’s better to use variants, as in the present case

            – egreg
            May 26 at 15:19











          • @PhelypeOleinik Yes, of course

            – egreg
            May 27 at 11:04


















          5


















          When you do:



          seq_put_right:Nn mySeq dim_eval:n box_wd:N myBox 


          what you are appending to your sequence is the token list dim_eval:nbox_wd:NmyBox (the tokens are dim_eval:n, with catcode 1, box_wd:N, myBox and with catcode 2). The final dim_eval:n is evaluated too late, once the loop has been fully executed and you do seq_use:Nn mySeq ,~. At this point, myBox contains the digit 9, hence what you saw. As egreg said (faster than me), replace seq_put_right:Nn with seq_put_right:Nx to evaluate dim_eval:n inside the loop, when myBox still contains the relevant digit.



          You have to realize that your sequence variable mySeq does not contain any length at all: it contains n times the same token list, which I explicitated above, with n=0 at first, then n=1, ..., and finally n=9. In other words, it contains n times the same “formula,” stored in the form of a token list. This formula is comparable to a function of one variable, the box variable myBox. Whenever you use seq_use:Nn mySeq ..., you put n copies of the same formula in the input stream (where n is the current length of mySeq), and when TeX expands one of the dim_eval:n tokens and processes all tokens resulting from this expansion, this yields a length (precisely: a 〈dimen〉) according to the formula and the contents of myBox at that point.



          At the end of your example, your code therefore computes n=9 times the same formula with the same value of myBox, an hbox containing the figure 9. In very explicit terms, your final seq_use:Nn call is equivalent to this:



          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox


          Calculating 9 times f(x) with the same function f and the same value of x gives 9 times the same result, hence the output you obtained.



          For the seq_use:Nn calls inside the loop, this is exactly the same, except that n is replaced by a number between 1 and 8, inclusive.



          Note: as people already told you, your variables don't respect the LaTeX3 coding guidelines. Read expl3.pdf and l3styleguide.pdf from here (the beginning of interface3.pdf is also pretty useful to read at first, but I suppose you've already seen it).






          share|improve this answer




























          • I got tired to tell the OP about following the guidelines

            – egreg
            May 26 at 8:00











          • @egreg Let's hope that with time comes wisdom. :-)

            – frougon
            May 26 at 8:02












          • @egreg, and frougon, why is it necessary to introduce additional complexity into your code (especially in a testing environment, here) and peer into it every time trying to distinguish your variables and functions from expl3-defined ones? On the contrary, regular naming (everyone had been using before expl3) looks easily distinguishable from expl3 naming, so the "guidelines" are more appropriate for the expl3 team/authors than for those who use the package (because the contrast in naming conventions makes the code easy to read; imposing same naming conventions on users is a mistake).

            – bp2017
            May 26 at 14:33












          • You say dim_eval:n is evaluated too late. But how late is too late? Is it evaluated at the end of the loop? If so, why do I get results at each iteration?

            – bp2017
            May 26 at 15:01






          • 2





            1) For code in a file that is never going to be a package, using l_my_ and g_my_ prefixes is probably acceptable, but the day you want to reuse such code with another one developed in the same way, you're trapped and have to rename everything. 2) The distinction between local and global assignments on the one hand, and local and global variables on the other hand, is very important. The naming convention helps a lot avoid errors. 3) If you want to understand well expansion, read the TeXbook (study each exercise!). LaTeX3 will become much clearer after that.

            – frougon
            May 26 at 18:35













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "85"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f492672%2fwhy-appending-box-dimensions-to-a-sequence-in-a-loop-makes-that-sequence-only%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown


























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4


















          You need to expand the value: use



          seq_put_right:Nx


          instead.



          What's the problem? If you do



          hbox_set:Nn l_tmpa_box A 
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box
          hbox_set:Nn l_tmpa_box AA
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box


          this results in the sequence to contain the following items (without the outer braces, as it would be displayed by seq_show:N l_tmpa_seq)



           dim_eval:n box_wd:N l_tmpa_box 
          dim_eval:n box_wd:N l_tmpa_box


          When the sequence is used, the width of the current contents of l_tmpa_box is employed: the value it had at the moment of assignment has never been mentioned.



          With seq_put_right:Nx you instead get the value frozen at the moment of the assignment.



          Would it be “better” to use



          exp_args:NNx seq_put_right:Nn l_tmpa_tl ...


          No. Using (or defining, in case of need) a variant is better style.






          share|improve this answer























          • 1





            @bp2017 In my opinion it’s better to use variants, as in the present case

            – egreg
            May 26 at 15:19











          • @PhelypeOleinik Yes, of course

            – egreg
            May 27 at 11:04















          4


















          You need to expand the value: use



          seq_put_right:Nx


          instead.



          What's the problem? If you do



          hbox_set:Nn l_tmpa_box A 
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box
          hbox_set:Nn l_tmpa_box AA
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box


          this results in the sequence to contain the following items (without the outer braces, as it would be displayed by seq_show:N l_tmpa_seq)



           dim_eval:n box_wd:N l_tmpa_box 
          dim_eval:n box_wd:N l_tmpa_box


          When the sequence is used, the width of the current contents of l_tmpa_box is employed: the value it had at the moment of assignment has never been mentioned.



          With seq_put_right:Nx you instead get the value frozen at the moment of the assignment.



          Would it be “better” to use



          exp_args:NNx seq_put_right:Nn l_tmpa_tl ...


          No. Using (or defining, in case of need) a variant is better style.






          share|improve this answer























          • 1





            @bp2017 In my opinion it’s better to use variants, as in the present case

            – egreg
            May 26 at 15:19











          • @PhelypeOleinik Yes, of course

            – egreg
            May 27 at 11:04













          4














          4










          4









          You need to expand the value: use



          seq_put_right:Nx


          instead.



          What's the problem? If you do



          hbox_set:Nn l_tmpa_box A 
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box
          hbox_set:Nn l_tmpa_box AA
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box


          this results in the sequence to contain the following items (without the outer braces, as it would be displayed by seq_show:N l_tmpa_seq)



           dim_eval:n box_wd:N l_tmpa_box 
          dim_eval:n box_wd:N l_tmpa_box


          When the sequence is used, the width of the current contents of l_tmpa_box is employed: the value it had at the moment of assignment has never been mentioned.



          With seq_put_right:Nx you instead get the value frozen at the moment of the assignment.



          Would it be “better” to use



          exp_args:NNx seq_put_right:Nn l_tmpa_tl ...


          No. Using (or defining, in case of need) a variant is better style.






          share|improve this answer
















          You need to expand the value: use



          seq_put_right:Nx


          instead.



          What's the problem? If you do



          hbox_set:Nn l_tmpa_box A 
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box
          hbox_set:Nn l_tmpa_box AA
          seq_put_right:Nn l_tmpa_seq dim_eval:n box_wd:N l_tmpa_box


          this results in the sequence to contain the following items (without the outer braces, as it would be displayed by seq_show:N l_tmpa_seq)



           dim_eval:n box_wd:N l_tmpa_box 
          dim_eval:n box_wd:N l_tmpa_box


          When the sequence is used, the width of the current contents of l_tmpa_box is employed: the value it had at the moment of assignment has never been mentioned.



          With seq_put_right:Nx you instead get the value frozen at the moment of the assignment.



          Would it be “better” to use



          exp_args:NNx seq_put_right:Nn l_tmpa_tl ...


          No. Using (or defining, in case of need) a variant is better style.







          share|improve this answer















          share|improve this answer




          share|improve this answer








          edited May 27 at 11:04

























          answered May 26 at 6:30









          egregegreg

          775k92 gold badges2020 silver badges3381 bronze badges




          775k92 gold badges2020 silver badges3381 bronze badges










          • 1





            @bp2017 In my opinion it’s better to use variants, as in the present case

            – egreg
            May 26 at 15:19











          • @PhelypeOleinik Yes, of course

            – egreg
            May 27 at 11:04












          • 1





            @bp2017 In my opinion it’s better to use variants, as in the present case

            – egreg
            May 26 at 15:19











          • @PhelypeOleinik Yes, of course

            – egreg
            May 27 at 11:04







          1




          1





          @bp2017 In my opinion it’s better to use variants, as in the present case

          – egreg
          May 26 at 15:19





          @bp2017 In my opinion it’s better to use variants, as in the present case

          – egreg
          May 26 at 15:19













          @PhelypeOleinik Yes, of course

          – egreg
          May 27 at 11:04





          @PhelypeOleinik Yes, of course

          – egreg
          May 27 at 11:04













          5


















          When you do:



          seq_put_right:Nn mySeq dim_eval:n box_wd:N myBox 


          what you are appending to your sequence is the token list dim_eval:nbox_wd:NmyBox (the tokens are dim_eval:n, with catcode 1, box_wd:N, myBox and with catcode 2). The final dim_eval:n is evaluated too late, once the loop has been fully executed and you do seq_use:Nn mySeq ,~. At this point, myBox contains the digit 9, hence what you saw. As egreg said (faster than me), replace seq_put_right:Nn with seq_put_right:Nx to evaluate dim_eval:n inside the loop, when myBox still contains the relevant digit.



          You have to realize that your sequence variable mySeq does not contain any length at all: it contains n times the same token list, which I explicitated above, with n=0 at first, then n=1, ..., and finally n=9. In other words, it contains n times the same “formula,” stored in the form of a token list. This formula is comparable to a function of one variable, the box variable myBox. Whenever you use seq_use:Nn mySeq ..., you put n copies of the same formula in the input stream (where n is the current length of mySeq), and when TeX expands one of the dim_eval:n tokens and processes all tokens resulting from this expansion, this yields a length (precisely: a 〈dimen〉) according to the formula and the contents of myBox at that point.



          At the end of your example, your code therefore computes n=9 times the same formula with the same value of myBox, an hbox containing the figure 9. In very explicit terms, your final seq_use:Nn call is equivalent to this:



          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox


          Calculating 9 times f(x) with the same function f and the same value of x gives 9 times the same result, hence the output you obtained.



          For the seq_use:Nn calls inside the loop, this is exactly the same, except that n is replaced by a number between 1 and 8, inclusive.



          Note: as people already told you, your variables don't respect the LaTeX3 coding guidelines. Read expl3.pdf and l3styleguide.pdf from here (the beginning of interface3.pdf is also pretty useful to read at first, but I suppose you've already seen it).






          share|improve this answer




























          • I got tired to tell the OP about following the guidelines

            – egreg
            May 26 at 8:00











          • @egreg Let's hope that with time comes wisdom. :-)

            – frougon
            May 26 at 8:02












          • @egreg, and frougon, why is it necessary to introduce additional complexity into your code (especially in a testing environment, here) and peer into it every time trying to distinguish your variables and functions from expl3-defined ones? On the contrary, regular naming (everyone had been using before expl3) looks easily distinguishable from expl3 naming, so the "guidelines" are more appropriate for the expl3 team/authors than for those who use the package (because the contrast in naming conventions makes the code easy to read; imposing same naming conventions on users is a mistake).

            – bp2017
            May 26 at 14:33












          • You say dim_eval:n is evaluated too late. But how late is too late? Is it evaluated at the end of the loop? If so, why do I get results at each iteration?

            – bp2017
            May 26 at 15:01






          • 2





            1) For code in a file that is never going to be a package, using l_my_ and g_my_ prefixes is probably acceptable, but the day you want to reuse such code with another one developed in the same way, you're trapped and have to rename everything. 2) The distinction between local and global assignments on the one hand, and local and global variables on the other hand, is very important. The naming convention helps a lot avoid errors. 3) If you want to understand well expansion, read the TeXbook (study each exercise!). LaTeX3 will become much clearer after that.

            – frougon
            May 26 at 18:35
















          5


















          When you do:



          seq_put_right:Nn mySeq dim_eval:n box_wd:N myBox 


          what you are appending to your sequence is the token list dim_eval:nbox_wd:NmyBox (the tokens are dim_eval:n, with catcode 1, box_wd:N, myBox and with catcode 2). The final dim_eval:n is evaluated too late, once the loop has been fully executed and you do seq_use:Nn mySeq ,~. At this point, myBox contains the digit 9, hence what you saw. As egreg said (faster than me), replace seq_put_right:Nn with seq_put_right:Nx to evaluate dim_eval:n inside the loop, when myBox still contains the relevant digit.



          You have to realize that your sequence variable mySeq does not contain any length at all: it contains n times the same token list, which I explicitated above, with n=0 at first, then n=1, ..., and finally n=9. In other words, it contains n times the same “formula,” stored in the form of a token list. This formula is comparable to a function of one variable, the box variable myBox. Whenever you use seq_use:Nn mySeq ..., you put n copies of the same formula in the input stream (where n is the current length of mySeq), and when TeX expands one of the dim_eval:n tokens and processes all tokens resulting from this expansion, this yields a length (precisely: a 〈dimen〉) according to the formula and the contents of myBox at that point.



          At the end of your example, your code therefore computes n=9 times the same formula with the same value of myBox, an hbox containing the figure 9. In very explicit terms, your final seq_use:Nn call is equivalent to this:



          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox


          Calculating 9 times f(x) with the same function f and the same value of x gives 9 times the same result, hence the output you obtained.



          For the seq_use:Nn calls inside the loop, this is exactly the same, except that n is replaced by a number between 1 and 8, inclusive.



          Note: as people already told you, your variables don't respect the LaTeX3 coding guidelines. Read expl3.pdf and l3styleguide.pdf from here (the beginning of interface3.pdf is also pretty useful to read at first, but I suppose you've already seen it).






          share|improve this answer




























          • I got tired to tell the OP about following the guidelines

            – egreg
            May 26 at 8:00











          • @egreg Let's hope that with time comes wisdom. :-)

            – frougon
            May 26 at 8:02












          • @egreg, and frougon, why is it necessary to introduce additional complexity into your code (especially in a testing environment, here) and peer into it every time trying to distinguish your variables and functions from expl3-defined ones? On the contrary, regular naming (everyone had been using before expl3) looks easily distinguishable from expl3 naming, so the "guidelines" are more appropriate for the expl3 team/authors than for those who use the package (because the contrast in naming conventions makes the code easy to read; imposing same naming conventions on users is a mistake).

            – bp2017
            May 26 at 14:33












          • You say dim_eval:n is evaluated too late. But how late is too late? Is it evaluated at the end of the loop? If so, why do I get results at each iteration?

            – bp2017
            May 26 at 15:01






          • 2





            1) For code in a file that is never going to be a package, using l_my_ and g_my_ prefixes is probably acceptable, but the day you want to reuse such code with another one developed in the same way, you're trapped and have to rename everything. 2) The distinction between local and global assignments on the one hand, and local and global variables on the other hand, is very important. The naming convention helps a lot avoid errors. 3) If you want to understand well expansion, read the TeXbook (study each exercise!). LaTeX3 will become much clearer after that.

            – frougon
            May 26 at 18:35














          5














          5










          5









          When you do:



          seq_put_right:Nn mySeq dim_eval:n box_wd:N myBox 


          what you are appending to your sequence is the token list dim_eval:nbox_wd:NmyBox (the tokens are dim_eval:n, with catcode 1, box_wd:N, myBox and with catcode 2). The final dim_eval:n is evaluated too late, once the loop has been fully executed and you do seq_use:Nn mySeq ,~. At this point, myBox contains the digit 9, hence what you saw. As egreg said (faster than me), replace seq_put_right:Nn with seq_put_right:Nx to evaluate dim_eval:n inside the loop, when myBox still contains the relevant digit.



          You have to realize that your sequence variable mySeq does not contain any length at all: it contains n times the same token list, which I explicitated above, with n=0 at first, then n=1, ..., and finally n=9. In other words, it contains n times the same “formula,” stored in the form of a token list. This formula is comparable to a function of one variable, the box variable myBox. Whenever you use seq_use:Nn mySeq ..., you put n copies of the same formula in the input stream (where n is the current length of mySeq), and when TeX expands one of the dim_eval:n tokens and processes all tokens resulting from this expansion, this yields a length (precisely: a 〈dimen〉) according to the formula and the contents of myBox at that point.



          At the end of your example, your code therefore computes n=9 times the same formula with the same value of myBox, an hbox containing the figure 9. In very explicit terms, your final seq_use:Nn call is equivalent to this:



          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox


          Calculating 9 times f(x) with the same function f and the same value of x gives 9 times the same result, hence the output you obtained.



          For the seq_use:Nn calls inside the loop, this is exactly the same, except that n is replaced by a number between 1 and 8, inclusive.



          Note: as people already told you, your variables don't respect the LaTeX3 coding guidelines. Read expl3.pdf and l3styleguide.pdf from here (the beginning of interface3.pdf is also pretty useful to read at first, but I suppose you've already seen it).






          share|improve this answer
















          When you do:



          seq_put_right:Nn mySeq dim_eval:n box_wd:N myBox 


          what you are appending to your sequence is the token list dim_eval:nbox_wd:NmyBox (the tokens are dim_eval:n, with catcode 1, box_wd:N, myBox and with catcode 2). The final dim_eval:n is evaluated too late, once the loop has been fully executed and you do seq_use:Nn mySeq ,~. At this point, myBox contains the digit 9, hence what you saw. As egreg said (faster than me), replace seq_put_right:Nn with seq_put_right:Nx to evaluate dim_eval:n inside the loop, when myBox still contains the relevant digit.



          You have to realize that your sequence variable mySeq does not contain any length at all: it contains n times the same token list, which I explicitated above, with n=0 at first, then n=1, ..., and finally n=9. In other words, it contains n times the same “formula,” stored in the form of a token list. This formula is comparable to a function of one variable, the box variable myBox. Whenever you use seq_use:Nn mySeq ..., you put n copies of the same formula in the input stream (where n is the current length of mySeq), and when TeX expands one of the dim_eval:n tokens and processes all tokens resulting from this expansion, this yields a length (precisely: a 〈dimen〉) according to the formula and the contents of myBox at that point.



          At the end of your example, your code therefore computes n=9 times the same formula with the same value of myBox, an hbox containing the figure 9. In very explicit terms, your final seq_use:Nn call is equivalent to this:



          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox ,~
          dim_eval:n box_wd:N myBox


          Calculating 9 times f(x) with the same function f and the same value of x gives 9 times the same result, hence the output you obtained.



          For the seq_use:Nn calls inside the loop, this is exactly the same, except that n is replaced by a number between 1 and 8, inclusive.



          Note: as people already told you, your variables don't respect the LaTeX3 coding guidelines. Read expl3.pdf and l3styleguide.pdf from here (the beginning of interface3.pdf is also pretty useful to read at first, but I suppose you've already seen it).







          share|improve this answer















          share|improve this answer




          share|improve this answer








          edited May 26 at 20:35

























          answered May 26 at 6:39









          frougonfrougon

          8,6751 gold badge14 silver badges27 bronze badges




          8,6751 gold badge14 silver badges27 bronze badges















          • I got tired to tell the OP about following the guidelines

            – egreg
            May 26 at 8:00











          • @egreg Let's hope that with time comes wisdom. :-)

            – frougon
            May 26 at 8:02












          • @egreg, and frougon, why is it necessary to introduce additional complexity into your code (especially in a testing environment, here) and peer into it every time trying to distinguish your variables and functions from expl3-defined ones? On the contrary, regular naming (everyone had been using before expl3) looks easily distinguishable from expl3 naming, so the "guidelines" are more appropriate for the expl3 team/authors than for those who use the package (because the contrast in naming conventions makes the code easy to read; imposing same naming conventions on users is a mistake).

            – bp2017
            May 26 at 14:33












          • You say dim_eval:n is evaluated too late. But how late is too late? Is it evaluated at the end of the loop? If so, why do I get results at each iteration?

            – bp2017
            May 26 at 15:01






          • 2





            1) For code in a file that is never going to be a package, using l_my_ and g_my_ prefixes is probably acceptable, but the day you want to reuse such code with another one developed in the same way, you're trapped and have to rename everything. 2) The distinction between local and global assignments on the one hand, and local and global variables on the other hand, is very important. The naming convention helps a lot avoid errors. 3) If you want to understand well expansion, read the TeXbook (study each exercise!). LaTeX3 will become much clearer after that.

            – frougon
            May 26 at 18:35


















          • I got tired to tell the OP about following the guidelines

            – egreg
            May 26 at 8:00











          • @egreg Let's hope that with time comes wisdom. :-)

            – frougon
            May 26 at 8:02












          • @egreg, and frougon, why is it necessary to introduce additional complexity into your code (especially in a testing environment, here) and peer into it every time trying to distinguish your variables and functions from expl3-defined ones? On the contrary, regular naming (everyone had been using before expl3) looks easily distinguishable from expl3 naming, so the "guidelines" are more appropriate for the expl3 team/authors than for those who use the package (because the contrast in naming conventions makes the code easy to read; imposing same naming conventions on users is a mistake).

            – bp2017
            May 26 at 14:33












          • You say dim_eval:n is evaluated too late. But how late is too late? Is it evaluated at the end of the loop? If so, why do I get results at each iteration?

            – bp2017
            May 26 at 15:01






          • 2





            1) For code in a file that is never going to be a package, using l_my_ and g_my_ prefixes is probably acceptable, but the day you want to reuse such code with another one developed in the same way, you're trapped and have to rename everything. 2) The distinction between local and global assignments on the one hand, and local and global variables on the other hand, is very important. The naming convention helps a lot avoid errors. 3) If you want to understand well expansion, read the TeXbook (study each exercise!). LaTeX3 will become much clearer after that.

            – frougon
            May 26 at 18:35

















          I got tired to tell the OP about following the guidelines

          – egreg
          May 26 at 8:00





          I got tired to tell the OP about following the guidelines

          – egreg
          May 26 at 8:00













          @egreg Let's hope that with time comes wisdom. :-)

          – frougon
          May 26 at 8:02






          @egreg Let's hope that with time comes wisdom. :-)

          – frougon
          May 26 at 8:02














          @egreg, and frougon, why is it necessary to introduce additional complexity into your code (especially in a testing environment, here) and peer into it every time trying to distinguish your variables and functions from expl3-defined ones? On the contrary, regular naming (everyone had been using before expl3) looks easily distinguishable from expl3 naming, so the "guidelines" are more appropriate for the expl3 team/authors than for those who use the package (because the contrast in naming conventions makes the code easy to read; imposing same naming conventions on users is a mistake).

          – bp2017
          May 26 at 14:33






          @egreg, and frougon, why is it necessary to introduce additional complexity into your code (especially in a testing environment, here) and peer into it every time trying to distinguish your variables and functions from expl3-defined ones? On the contrary, regular naming (everyone had been using before expl3) looks easily distinguishable from expl3 naming, so the "guidelines" are more appropriate for the expl3 team/authors than for those who use the package (because the contrast in naming conventions makes the code easy to read; imposing same naming conventions on users is a mistake).

          – bp2017
          May 26 at 14:33














          You say dim_eval:n is evaluated too late. But how late is too late? Is it evaluated at the end of the loop? If so, why do I get results at each iteration?

          – bp2017
          May 26 at 15:01





          You say dim_eval:n is evaluated too late. But how late is too late? Is it evaluated at the end of the loop? If so, why do I get results at each iteration?

          – bp2017
          May 26 at 15:01




          2




          2





          1) For code in a file that is never going to be a package, using l_my_ and g_my_ prefixes is probably acceptable, but the day you want to reuse such code with another one developed in the same way, you're trapped and have to rename everything. 2) The distinction between local and global assignments on the one hand, and local and global variables on the other hand, is very important. The naming convention helps a lot avoid errors. 3) If you want to understand well expansion, read the TeXbook (study each exercise!). LaTeX3 will become much clearer after that.

          – frougon
          May 26 at 18:35






          1) For code in a file that is never going to be a package, using l_my_ and g_my_ prefixes is probably acceptable, but the day you want to reuse such code with another one developed in the same way, you're trapped and have to rename everything. 2) The distinction between local and global assignments on the one hand, and local and global variables on the other hand, is very important. The naming convention helps a lot avoid errors. 3) If you want to understand well expansion, read the TeXbook (study each exercise!). LaTeX3 will become much clearer after that.

          – frougon
          May 26 at 18:35



















          draft saved

          draft discarded















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f492672%2fwhy-appending-box-dimensions-to-a-sequence-in-a-loop-makes-that-sequence-only%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown









          Popular posts from this blog

          Tamil (spriik) Luke uk diar | Nawigatjuun

          Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

          Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?