COMPGROUPS.NET | Post | Groups | Users | Stream | Browse | About | |

### advance a counter from a macro

• Email
• Follow

This is so basic I'm ashamed to ask, but I know people
here can answer in no time, so I'll shut up my ego and ask.
Consider

\lll=-1
\ifnum\lll=0 ZZZ \else PPP \fi

\lll=-1
\showthe\lll
\ifnum\lll=0 ZZZ \else PPP \fi

\lll=-1
\showthe\lll
\ifnum\lll=0 ZZZ \else PPP \fi

\bye

I expected "ZZZ  ZZZ  ZZZ" but I get  "PPP PPP ZZZ"
Why??

Piero

 0
Reply pierodancona (12) 9/24/2008 7:52:04 PM

See related articles to this posting

pierodancona@gmail.com a =E9crit :
> This is so basic I'm ashamed to ask, but I know people
> here can answer in no time, so I'll shut up my ego and ask.
> Consider
>
>
> \lll=3D-1
> \ifnum\lll=3D0 ZZZ \else PPP \fi
>
> \lll=3D-1
> \showthe\lll
> \ifnum\lll=3D0 ZZZ \else PPP \fi
>
> \lll=3D-1
> \showthe\lll
> \ifnum\lll=3D0 ZZZ \else PPP \fi
>
> \bye
>
> I expected "ZZZ  ZZZ  ZZZ" but I get  "PPP PPP ZZZ"
> Why??
>  =20

A \relax is wiser after a number to avoid unexpected expansion of \ifnum =
:


 0

> > Why??
>
> A \relax is wiser after a number to avoid unexpected expansion of \ifnum :
>

Yes!
Thank you. I can go to sleep now

Piero


 0
Reply pierodancona (12) 9/24/2008 9:08:25 PM

<pierodancona@gmail.com> wrote:

> This is so basic I'm ashamed to ask, but I know people
> here can answer in no time, so I'll shut up my ego and ask.
> Consider
>
>
> \lll=-1
> \ifnum\lll=0 ZZZ \else PPP \fi
>
> \lll=-1
> \showthe\lll
> \ifnum\lll=0 ZZZ \else PPP \fi
>
> \lll=-1
> \showthe\lll
> \ifnum\lll=0 ZZZ \else PPP \fi
>
> \bye
>
> I expected "ZZZ  ZZZ  ZZZ" but I get  "PPP PPP ZZZ"
> Why??

\lll=-1 \ADV\ifnum\lll=0 ZZZ \else PPP \fi

and, after the initial assignment, it expands to

\global\advance\lll by 1\ifnum\lll=0 ZZZ \else PPP \fi

Now TeX expands tokens after the 1, as explained in the TeXbook;
therefore the conditional is evaluated when the value of \lll is
still -1.

A proper way to define \ADV is

or

(in a context where @ has category code 11). In the first case
the space will be ignored, in the second case the number specification
ends at the token \@ne which is not expandable (Plain TeX and LaTeX
define it by "\chardef\@ne=1").

In the second case the "\showthe\lll" is irrelevant, but in the third
one it stops the search for a number specification, since \showthe does
not expand to a <number>; therefore the assignment \lll=0 is performed
and the conditional is evaluated with the intended value.

Ciao
Enrico

 0
Reply gregorio (1366) 9/24/2008 9:19:18 PM
 comp.text.tex 36139 articles. 68 followers. Post

3 Replies
52 Views

Similar Articles

[PageSpeed] 46

• Email
• Follow

Similar Artilces:

Re: Problem with macro logical condition : passing a counter in the macro
Paul explains well the issues, and these are things one must understand in order to use the macro facility with confidence. However, you might find yourself moving in the direction of a quick fix by simply removing the percent signs in your Condition 1 and Condition 2 blocks. On Thu, 8 Jul 2004 01:33:20 -0400, Paul M. Dorfman <sashole@BELLSOUTH.NET> wrote: >Dominic, > >You are trying to use a macro assembling Data step code based on the value >of a Data step variable before the Data step has run. Note that the entire >activity of your macro compilation ends before the S...

Problem with macro logical condition : passing a counter in the macro from the data step
Hi, I have that little piece of code as an example (see below). In the macro 'ma_create' I want to use the variable count that is created in the data step 'test'. Basically count in that exemple is set to _n_. I know that count is seen correctly in the macro because I generate the variable check is has the right value. Still logical operation that requires the value of count fail. In execution of the macro, count is always seen as greater than the macro variable days which is set in that example to 5. Why does the code only excute condition 1 (count is always se...

You have been complaining about this class even before you took it. Lets work on these awful examples, so the "Ivory Billed Woodpeckers" can see them and improve this course. We can start with the example you refer to. What macro technique was being demonstrated? What would be a better example? When we beat this one to death we can move on to other irritating examples. On 9/5/08, Toby Dunn <tobydunn@hotmail.com> wrote: > Cherish, > > This is one of those examples I saw and hated in the Advanced Macro class > I attend last week. No macro is needed at all. Idea...

I have to create a lot of similar tables that only differs by type and name of each column (ok, I guess that _is_ the difference between tables). I create these tables by creating a class for a row and then letting a std::vector hold objects of these classes. As I have to write quite a lot I would like to use macros for this. Below I have shown how most of it works. I just cannot figure out a good way of keeping the name of each column. I'm hoping somebody have a great idea on how to accomplish this :-) --- table_row.cc --- #include <iostream> #include <string> #defin...