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 (1367) 9/24/2008 9:19:18 PM
 comp.text.tex 37284 articles. 72 followers.

3 Replies
104 Views

Similar Articles

[PageSpeed] 53

• 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...

Have there ever been any experiments with something like: a. "semi-colon eating" macros #define foo(a, b;) case ((a)+(b)): foo(a, b); becomes case ((a)+(b)): b. "block taking" macros: #define foo(a, b, {c}) switch (a) \ { case (b): { c } break; default: blah; } foo(a, b) { outer1; { inner; } outer2; } becomes: switch (a) { case (b): { outer1; { inner; } outer2; } break; default: blah; } Maybe somebody thought of something like this before but they decide...

Macro question: How to created macro variables from a macro
The macro below works when I don't use the CI variable and instead hard code the size of the confidence interval. When I add the CI= option in the macro it doesn't work, I'm guessing for a number of reasons, such as attempting to create a variable outside of a datastep and, perhaps, treating said variables as both a number and as text. Any help appreciated. Thanks. %MACRO UNIVAR(DATA=ONE, VAR=EXP, CI=95); %LET LBCI=(100 - &CI)/2 ; %LET UBCI= &CI + &LBCI ; PROC UNIVARIATE DATA=WORK.&DATA NOPRINT; CLASS S ; VAR &a...

macro to define other macros

macro inside macro
Hi there, I often write app with GObject. Well, of course, GObject is hard to use. So I thought about making a set of macros to make this job easier. Just like this (assume the class is 'GtkButton'): #define NAME GTK #define SPACE BUTTON #define Type GtkButton #define name_space gtk_button static void name_space ## _init (Type *self) { /* do something */ } Well, GObject always needs some macros to do something usual. So can I write these macros like this? #define NAME##_IS_##SPACE ... #define NAME##_IS_##SPACE##CLASS ... Maybe I need a try. But my l...

Macros calling macros
Hi, I have written a couple of small macros that does some text output and needs to indent. It kind of looks like the following :- (defmacro with-indent (&rest args) (combine (indent+) ,@args (indent-))) (defmacro gen-block (block-type block-name &rest args) (combine (gen-begin block-type block-name) (with-indent ,@args) (gen-end block-type))) ; indent+/- just alter a variable which is indent level. gen-begin/end make "begin/end blah" strings. On the surface of it, this works fine. I can get gen-block to make begin/end statements for home mad...

Macro to rerun a macro
You know what I would like to have (among other things, of course) is a way to have a macro button on my toolbar that when I click it, it runs whatever the last macro was that I ran, not including itself. Has anyone looked into that? The reason is that I may not have a button or hotkey tied to a particular macro, and click-finding it gets old. So, thus my idea. Any thoughts out there? WT You could modify each of your macros so that they leave a trail. Each macro closes by writing its name into a semipermanent location, either a registry location or in a temporary text file. Th...

In this thread, I will provide some potentially useful Naturally Speaking advanced scripting macros for Windows. You must have Dragon NaturallySpeaking 8 Professional (or maybe prior Professional versions). My methods are subject to change as I learn the specific scripting capabilities of the speech recognition program. I will try to post any corrections/improvements to an already posted macro under that macro's original subthread. If a macro will not work on your system, please advise and I will be happy to reformulate/rewrite or offer assistance to get the thing working on your...

macros that build macros
Back before C++ templates, I was taught a trick whereby one built C macros that built other C macros. I can't remember how the heck we did it. The problem is that there seems to be no standard way to include a '#' or '#define' in the output of a macro. The other problem is that we might have been using some sort of non-standard preprocessor trick to do it. Obliged if anyone can point me in the right direction or tell me what I'm trying to do is impossible. -thant On Sep 11, 11:08 am, Thant Tessman <a...@standarddeviance.com> wrote: > Back before C++ te...

Macros in Macros in Gambit
I'm working in Gambit and have been experiencing this problem with what seems to be macros being used inside of macros. The code below throws and error when included saying '*** ERROR -- Unbound variable: dbind-func' , but if i run them in the repl one at a time everything works fine. Any ideas? (define-macro (with-gensyms syms . body) (let ,(map (lambda (a) (,a (gensym))) syms) ,@body)) (define (dbind-func form var) (with-gensyms (v) (cond ((symbol? form) ((,form ,var))) ((pair? form) (append (dbind-func (car form) (car ,var)) (dbind-func (cdr ...

Macro Variable Counter Resolving to ** ?
Hi, I wrote a macro that creates a dataset, and need to make the number of observations in that dataset available a a variable inside the macro: %macro PValueLoop; .... /*Create dataset to be analysed. */ data CorrelationData; set Head2SHT1; where ...; run; /* Determine # of observations in dataset. */ data _null_; set CorrelationData end=eof; o+1; oo=left(put(o,2.)); if eof then call symput ('Total',oo); run; .... /* Format and relabel correlation results. */ data FormatResults; set CorrResults; NumObs=&&Total; run; %mend PValueLoop; Why do I get ** as the output? I tri...

Macro/no macro challenge
Subject: Macro/no macro challenge Related thread: Re: Macro [ab]usage (was: (OT) old style macro is still working) Warning: Long and probably hard reading with work if you accept the challenge Respondent: Ian_Whitlock@comcast.net I recently received a non-macro solutions to the splitting and renaming problems that have been discussed under "Re: Macro [ab] usage (was: (OT) old style macro is still working)", and was asked for my thoughts. In previous messages to SAS-L I gave what I thought was adequate criticism to the related non-macro solution...

macro in macro remotely
Hi all, OK heres an easy one (or 2) (I hope): How do I invoke a macro in a macro? eg I have an existing macro named "stuff" and i want macro blah to run in it. So: %macro blah; ..is it %stuff, %%stuff, %stuff;, or %%stuff;? %mend blah; %blah and second: I have a local macro, and I want the embedded macro to run on a remote server eg Existing local macro named "stuff" %macro blah; ..is it rsubmit; %stuff, %%stuff, %stuff;, or %%stuff; endrsubmit? %mend blah; %blah My head starts to spin about this time..... All tips greatly appreciated. Cheers L_B &q...

Setf macro macro
I'm trying to piece together a macro to define setf macros. As I have quite a few of these that will all be (relatively) the same, give or take a couple extra arguments. Here is the simple macro I have so far (using LispWorks): (defmacro defsetf-callback (callback &rest params) (defsetf ,callback (,@params) (name) (,callback ,,@params (make-pointer :symbol-name ,name)))) This is 95% correct: (pprint (macroexpand-1 '(defsetf-callback my-callback x))) => (DEFSETF MY-CALLBACK (X) (NAME) (,CALLBACK ,X (MAKE-POINTER :SYMBOL-NAME ,NAME))) Everything is correct *exc...

macro that writes macros
Hi, I'm learning lisp and tried to make this little program to write a web page: (defmacro new-tag (name) (let ((sname (string-downcase (symbol-name name)))) (defmacro ,name (&rest content) `(progn (format t "<~a>~%" ,',sname) ,@content (format t "</~a>~%" ,',sname))))) (new-tag html) (new-tag head) (new-tag title) (new-tag body) (new-tag p) ;; With that, now a web page can be "self-generated": (html (head (title "My web page")) (body (p "Hello world"))) And it works. But then I th...

Listcomprehension-macro? Macros with args inside macro-name?
I am trying to learn lisp macros and I generally find listcomprehensions to be elegant and they dont exist in lisp. This has to be a macro right? Cant be a function? But how would I get started when it needs the arguments inside its name? In Python: >>> [x**2 for x in [12,31,2,33] if x > 20] [961, 1089] >>> [expr loop &optional cond] Could I perhaps make a macro [ that triggers another macro? (defmacro [ () ((let listcomp (read until next ]) (filter (cond) (mapcar expr loop))) defn noob wrote: > I am trying to learn lisp macros and I generally find...

macro name from macro?
Hi, Is it possible to get the name of the macro from that macro itself. Thank you in advance. On 20 Sep 2003 04:14:58 -0700, dsenthil_cs@hotmail.com (D Senthil Kumar) wrote in comp.lang.c: > Hi, > Is it possible to get the name of the macro from that macro itself. > Thank you in advance. Sure, by reading the definition of the macro. If that is not what you meant, post again. Your question is very ambiguous, so use more words and perhaps even a small code snippet as an example of what you want to do. It is clear in your mind, but you have not made it clear to others. -- Jack ...

Re: Macro question: How to created macro variables from a macro
Hi Kevin, A couple of syntax changes, see notes below. Also, OPTION MPRINT; even without the dataset to actually read can show you if the text substitutions from the macro goodies are as you want them to be. %MACRO UNIVAR(DATA=,VAR=,CI=); %* only placeholders needed here ; %* add actual values when called ; %LET LBCI=%eval((100 - &CI)/2); %* pre-resolve with eval ; %LET UBCI=%eval(&CI + &LBCI); %* pre-resolve with eval ; PROC UNIVARIATE DATA=WORK.&DATA NOPRINT; CLASS S; VAR &VAR; ...

macro within a macro

macros within macros
L.S., Suppose I have a macro M1 that defines a macro. Lets define a new macro using this macro: (M1 new+ (number? number?) +) Now, suppose I'd like to redefine the new+ macro, using the previous definition of of itself: (M1 new+ (string? number?) (lamda (a b) (string-append a (number->string b)))) At this point, I'd like to see: (new+ 2 3) -> 5 (new+ "a" 2) -> "a2" I have an implementation, which is about: (M1 new+ (number? number?) +) (M1 newnew+ new+ (string? number?) (lamda (a b) (string-append a (number->string b)))) But this is not ...

macro as a product of macros
Hello, I don't know how I can create a macro as a product of 3 previous macros. I have: %LET BandRec=5; %LET BandFre=3; %LET BandMon=4; The 4th macro should be the product of: BandRec*BandFre*BandMon. Therefore the result must be 60. Can you help me please? Thank you. Hi , These are macro variables not macros. Try this.... %LET BandRec=5; %LET BandFre=3; %LET BandMon=4; %let result=%eval(&bandrec*&bandfre*&bandmon); %put &result; Thanks shiva On Jul 31, 9:22=A0am, shiva <shiva.said...@gmail.com> wrote: > Hi , > > These are macro variables not macr...