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

RE: st: RE: what is c_local?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: what is c_local?
Date   Fri, 12 Dec 2003 16:03:21 -0000

David Kantor

> I suppose that what -c_local- does can be also done using
> -return- (plus
> some copying of values, if desired). Perhaps -c_local- was
> around before
> -return- was introduced.

Best keep these separate. The point of -return- is to leave
stuff in memory once a program has finished, that is,
until another r-class program overwrites it, or the
session finishes. That is for a user to pick up interactively,
or for other programs to do so -- if desired.

-return- is generous to friends and strangers alike,
irrespective of demand.

-c_local- is generous to a partner only, and requires both
to communicate deliberately and unambiguously.

>
> This discussion reminds me of something I had experimented
> with recently. I
> have written a lot of code with commands that appended a local:
>
>   local mystuff "`mystuff' other_stuff"
>
> and I was doing that repeatedly, incrementally appending
> more and more
> additional text onto mystuff. So I wondered whether this could be
> programmed.  I did not succeed at the time, but just now I
> realized what I
> needed to do: the name of the local as well as the contents
> need to be
> passed separately.  Here is the code:
>
> program def append_local
> syntax , name(string) contents(string) newstuff(string)
> c_local `name' "`contents' `newstuff'"
> end
>
> Then you call it:
>
> append_local, name(mystuff) contents(`mystuff')
> newstuff(other_stuff)
>
> This is a bit unwieldy, and requires that you use it in a
> particular
> way.  So it's not worthwhile.
>
> I think that Statacorp might consider making a new
> (built-in) command to do
> this.  It would go like ...
>   append_local localname "stuff_to_be_appended"
>
> Thus, it would work just like -local-, but would append rather than
> replace.  (Is there already something like that -- that I
> am ignorant of?)
>
> (I might add that such a command might be coded so as to
> put the appended
> text right at the end, avoiding the re-evaluation and
> copying of the entire
> expression as in
>   -local mystuff "`mystuff' other_stuff"-,
> which can become very inefficient as the length of `mystuff' grows.)

This is for StataCorp, mostly. But if there's a case for append_local,
there's a case for prepend_local, and perhaps some others.
But I doubt it.

It seems to me that the existing way of appending, prepending,
etc. is nice and general, and very transparent. Since
it's at the heart of Stata programming, it would be a great
surprise if it was not coded to be done very very fast.

Nick
n.j.cox@durham.ac.uk

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index