Announcement

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

  • Local macro list and tuples

    I am in need of two different tuples lists, so I would like to store one set as a local and call the other in a different loop.

    Below is the command i am trying to store. I do not think it is storing the list because when I call the new local list in the second loop it does not recognize the local macro sp`i'. I am trying the following command to store the tuples (tuple1, tuple2, tuple3,...) to sp`i' (eg. sp1, sp2, sp3...) .

    tuples x y z w

    forval i =1/15 {
    local sp`i' `tuple`i''
    }

    As a bonus question is there a command to count the number of tuples created so I can make the indexing more flexible? So instead of 15 it would be max(tuples), or something similar.
    Thanks!

    [Tuples is a really cool command. Thanks whoever created it!!!]

  • #2
    tuples is from SSC, as you are asked to explain.

    ... whoever created it ... Not a mystery: the help explains:

    Joseph N. Luchman, Fors Marsh Group LLC
    [email protected]

    Daniel Klein, INCHER-Kassel, Universität Kassel
    [email protected]

    Nicholas J. Cox, Durham University
    [email protected]

    So thanks. And I really am just third author now.

    Is there a command to count the number of tuples created? No, but again the help explains:

    The number of macros created by tuples is returned in local macro ntuples.
    I can't reproduce your problem. This works for me. Output irrelevant to the question has been edited out.

    Code:
    . tuples x y z w
    
    . mac li
    _ntuples:       15
    _tuple15:       x y z w
    _tuple14:       x y z
    _tuple13:       x y w
    _tuple12:       x z w
    _tuple11:       y z w
    _tuple10:       x y
    _tuple9:        x z
    _tuple8:        x w
    _tuple7:        y z
    _tuple6:        y w
    _tuple5:        z w
    _tuple4:        x
    _tuple3:        y
    _tuple2:        z
    _tuple1:        w
    
    forval i = 1/15 {
         local sp`i' `tuple`i''
    }
    
    . mac li
    _sp15:          x y z w
    _sp14:          x y z
    _sp13:          x y w
    _sp12:          x z w
    _sp11:          y z w
    _sp10:          x y
    _sp9:           x z
    _sp8:           x w
    _sp7:           y z
    _sp6:           y w
    _sp5:           z w
    _sp4:           x
    _sp3:           y
    _sp2:           z
    _sp1:           w
    _ntuples:       15
    _tuple15:       x y z w
    _tuple14:       x y z
    _tuple13:       x y w
    _tuple12:       x z w
    _tuple11:       y z w
    _tuple10:       x y
    _tuple9:        x z
    _tuple8:        x w
    _tuple7:        y z
    _tuple6:        y w
    _tuple5:        z w
    _tuple4:        x
    _tuple3:        y
    _tuple2:        z
    _tuple1:        w
    To be fair, I can think of a way of reproducing your problem. If you create the local macros in one namespace (e.g. that of an interactive session) and then try to refer to them in another namespace (e.g in a do-file editor window), then that wouldn't work. The macros are local to each namespace and not visible elsewhere: that's what local means. There are ways around this, but by far the simplest is to work in the same namespace throughout.


    Comment


    • #3
      Thanks for the help! I was making the error somewhere else in the code. I did not know the "mac li" which is a really helpful debugger. Thanks!

      Comment

      Working...
      X