TCL variable scope ?

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL variable scope ?

  • Creator
    Topic
  • #49381
    John Hamilton
    Participant

      Ok, I have inherited a translation that is currently working but needs some modification.

      In this translation they have an iteration that collects the values of a DG1 sub filed into a value define in a tcl procedure.   It appears to be working.  The sum of  the text comments is getting stored into this tcl pre proc variable. At least in this low volume testing.  This translation has never been put into a production environment.

      My question is can you depend on a variable defined in a tcl procedure to hold it

    Viewing 3 reply threads
    • Author
      Replies
      • #61726
        Robert Kersemakers
        Participant

          Hi John,

          I have used these @ variables for a lot of things, including combining several text segments into one field. As I have never had any problem with these variables I really think these variables can be used as variables are used in any other language. Nothing wrong with it!

          Just be aware that these variables hold their value as long as the current translation is in progress. If the next message is translated and a new translation starts, the variables are gone!

          Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

        • #61727
          Chris Williams
          Participant

            A while back, I was really confused about using variables in xlates until I spoke with Jim The Great and Powerful Kosloskey. Here are some notes I took:

            Initialize before using.

            @varName

            Access via Source/Destination. Cannot use these directly as iteration counters. Exist throughout a particular instance of an xlate. Can also be accessed in tcl procs called from an xlate via xpmfetch and xpmstore.

            %g1

            Group iteration counters when used in paths. Set by iteration statement. It

          • #61728
            John Hamilton
            Participant

              Let me try this again.

              What I mean is.

              We have a copy with a TCL fragment that sets a variable.

              { { OP COPY }

                 { ERR 0 }

                 { PRE {

                     set hold_dg “”

                 }}

                 { IN {} }

                 { OUT {} }

              }

              Iter start stuff …

                     { { OP COPY }

                         { ERR 0 }

                         { PRE {

                             set DG1_3_0 [lindex $xlateInVals 0]

                             set DG1_3_1 [lindex $xlateInVals 1]

                             append hold_dg $DG1_3_0 $DG1_3_1,

                         }}

               { IN {{2(0).1(0).0(0).DG1(%s2).#3.[0]} {2(0).1(0).0(0).DG1(%s2).#3.[

              1]}} }

                         { OUT @buildlist }

              End of Inter  ….

              { { OP COPY }

                 { ERR 0 }

                 { PRE {

                     set  xlateOutVals

                   }}

                   { IN {} }

                   { OUT {{2(0).1(0).0(0).OBR.#18.[1]}} }

                }

                These are the only places the hold_dg variable is used.

                I only resubmit this because I find this used in another location.

                Is this a legal use of a variable ?

              1. #61729
                Charlie Bursell
                Participant

                  John:

                  The answer is yes, that is a legal use of a Tcl variable in the Xlate thread.  By definition all Tcl variables within translate are global, no need to define them as such.

                  If it is not working for you, it is something that needs to be looked at.  I use this paradigm all of the time.

                  If it is not working, try a few echo statement scattered around and see where it quits working.

              Viewing 3 reply threads
              • The forum ‘Cloverleaf’ is closed to new topics and replies.