Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Integer program arguments not interpreted as integers (macro expansion question)


From   Ryan Turner <[email protected]>
To   [email protected]
Subject   Re: st: RE: Integer program arguments not interpreted as integers (macro expansion question)
Date   Fri, 13 Sep 2013 12:55:47 -0400

Thank you Joe, now it makes sense!

On Sep 13, 2013, at 12:11 PM, Joe Canner <[email protected]> wrote:

> Ryan,
> 
> When you call your program you should not use parentheses:
> 
> . timer_start  99
> 
> When you call your program with parentheses, your program interprets the first argument as "(99)" and that doesn't work with -timer on-.  (You can do -set trace on- to see this.)  In the macro assignment the parenthesis are dropped in the interpretation of the argument as a number. You can remove the "macro insanity" line if you call it without the parentheses.
> 
> You call Mata functions with arguments in parentheses, which may be what you were thinking of.
> 
> Regards,
> Joe Canner
> Johns Hopkins University School of Medicine
> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Ryan Turner
> Sent: Friday, September 13, 2013 11:47 AM
> To: [email protected]
> Subject: st: Integer program arguments not interpreted as integers (macro expansion question)
> 
> Dear Statalist:
> 
> I avoid asking beginner questions on the list because I don't want to waste people's time (and I, ahem, don't consider myself a beginner); but can somebody explain this macro insanity below?  I know _what_ I did (used an equal sign to force an arithmetic reassignment to the first program argument), but I do not understand _why_ it is necessary (why a macro, not being in double quotes, is not interpreted as an integer when clearly an integer is the only thing that makes sense here).
> 
> The purpose of this program is to quietly get timer parameters into the return variables (e.g., for -display r(t1) r(nt1)-).  Admittedly it only saves one line of code (I don't need to call -timer list- after -timer on #-) but it is (severally) in the middle of a large program.
> 
> Best,
> Ryan
> 
> 
> capture program drop timer_start
> program timer_start
>    quietly {
>        local 1 = `1' // macro insanity
>        timer on `1'
>        timer list
>    }
> end
> 
> capture program drop timer_stop
> program timer_stop
>    quietly {
>        local 1 = `1' // macro insanity
>        timer off `1'
>        timer list
>    }
> end
> 
> // Call it with:
> timer clear
> timer_start(99)
> return list
> 
> sleep 2000
> timer_stop(99)
> return list
> 
> 
> --
> Ryan J. Turner <[email protected]>
> Engineering and Public Policy
> Carnegie Mellon University
> +1-412-304-5014 (C) | +1-484-483-3244 (GV)
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

--
Ryan J. Turner <[email protected]>
Engineering and Public Policy
Carnegie Mellon University
+1-412-304-5014 (C) | +1-484-483-3244 (GV)


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index