Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: what is c_local?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: what is c_local?
Date   Fri, 12 Dec 2003 13:25:42 -0000

-c_local- is not documented, not even "undocumented".
Here's my stab at explaining it.

Normally, local macros are precisely that: local
to the program or do file they are inside.

Thus, the rule is that local macros in
two or more different programs can be
considered totally independent; they don't
know about each other and they
can't interfere with each other. So you could have

program Buda
	...
	local kardos 1
	...
end

program Pest
	...
	local kardos 2
	...
end

and there is no conflict. When -Buda-
is running, one definition applies, and
similarly with -Pest-. Now let's suppose
that in fact -Buda- calls -Pest-

program Buda
	...
	local kardos 1
	....
	Pest
	...
	di `kardos'
end

This makes no difference. When -Buda-
hands over to -Pest-, nothing that -Pest-
does makes any difference to the value
of local macro kardos in -Buda-. The
display will show 1 (assuming, naturally,
that the example shows all code affecting
kardos).

Usually, this is exactly as you want it.
Sometimes, it is nice to be able to
have a way round the rule and to have
a way of passing information back
to a calling program. (There are of course
other ways of doing this, not least globals.)

Consider now

program Buda
	...
	local kardos 1
	....
	Pest
	...
	di `kardos'
end

program Pest
	...
	c_local kardos = 2
	...
end

What the -c_local- does is carry out
a macro definition in the calling program's
space. So the -display- will show 2.

Naturally, the example is silly. But it's
very often useful to hand some task
to a subroutine and get back the answer.

Warning: this is dangerous unless you really understand it.

Nick
[email protected]

dr kardos lászló

> i am not sure what c_local is, and my searches for it have
> failed. can anyone explain?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index