Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • questions about the dangerous, non-documented -clocal-

    I ran across a reference to the command clocal in the Statalist archive, but I can't find any examples of its use. Can someone provide an example?

    The Google search "clocal" site:stata.com/statalist/archive only returned one result: http://www.stata.com/statalist/archi.../msg00854.html. That result says "a search of the Statalist archives will throw up several examples [of clocal usage]", but alas, I couldn't find any.

    (I thought I saw something on the new Statalist about clocal, but I must have imagined it. Neither the built-in search nor the Google search "clocal" site:statalist.org return anything.)

    Is this command still in use? I didn't find clocal in either Stata13\ado or Stata12\ado (in Windows).

  • #2
    It's called c_local

    In fact, the post you cited was mine, and the typo was mine, so sorry about that. Normally I am not too bad at speling.

    It's still there, but search for c_local.

    Comment


    • #3
      I think what you are looking for is c_local. Nick Cox explains it here:

      http://www.stata.com/statalist/archi.../msg00385.html

      Comment


      • #4
        Aha! Thank you Nick and Alan.

        Comment


        • #5
          Since the topic is raised on c_local, is there a reverse of it? (Something to peek into a particular local of the caller's namespace).
          That would be so much more convenient then passing a dozen of parameters through syntax.
          All necessary information for this command is readily available in Stata. It is just a matter of whether it is exposed to the users/programmers.

          Thank you, Sergiy

          Comment


          • #6
            I guess I missed the threads on c_local back when they originally came up. This strikes me as an incredibly dangerous command; in fact any program using it probably could be called malware!

            But can somebody explain to me why or when you would ever legitimately want to do this? What does it accomplish that could not be safely accomplished by having the called program be rclass (or higher) and having it:

            return local name `"`deep_macro'"'

            and then letting the caller access that information from r()?

            Comment


            • #7
              Clyde, it is used extensively in StataCorp's files supplied with Stata. In 255 classes and commands for e.g. Stata 13. From what I see, they use it exclusively indirectly, as for example:
              Code:
                  c_local `hmac' = `h'
                  c_local `smac' = `s'
                  c_local `vmac' = string(`v', "%6.2f")
              so that the left-hand side of the assignment is always a product of some dereferencing. In the above example (from the color.class) all the LHS macros are supplied as arguments. It seems to me that the c_local is an early mechanism for passing a reference to a value, rather than the value itself, and should not be used otherwise.

              yes, it is super-very-mega dangerous, and I avoid it at all costs, but some times it is just convenient because of the Stata's macro rather then variable approach. Everything c_local is doing can be implemented otherwise, more transparently, but perhaps at a cost of a few more lines.

              Best, Sergiy

              Comment


              • #8
                Originally posted by Clyde Schechter View Post
                I guess I missed the threads on c_local back when they originally came up. This strikes me as an incredibly dangerous command; in fact any program using it probably could be called malware!

                But can somebody explain to me why or when you would ever legitimately want to do this? What does it accomplish that could not be safely accomplished by having the called program be rclass (or higher) and having it:

                return local name `"`deep_macro'"'

                and then letting the caller access that information from r()?
                c_local exists as a parsing/programming convenience tool.

                Certain internal Stata commands, such as syntax and even the local command, create and/or modify local macros. What if you wanted to write an ado-file which had the same ability? That's why c_local exists. Without it, there is no way for an ado-file to have the same ability as an internal command to set a local macro in its caller's space.


                The answer to Sergiy's question:

                Since the topic is raised on c_local, is there a reverse of it? (Something to peek into a particular local of the caller's namespace).
                No -- there is no ability to reference by name locals in the caller's namespace.

                Comment


                • #9

                  Originally posted by Alan Riley (StataCorp) View Post

                  c_local exists as a parsing/programming convenience tool.

                  Certain internal Stata commands, such as syntax and even the local command, create and/or modify local macros. What if you wanted to write an ado-file which had the same ability? That's why c_local exists. Without it, there is no way for an ado-file to have the same ability as an internal command to set a local macro in its caller's space.
                  Thanks, Alan. Makes perfect sense!

                  Comment

                  Working...
                  X