Working with xlateInVals and xlateOutVals

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Working with xlateInVals and xlateOutVals

  • Creator
    Topic
  • #53911
    Chris Williams
    Participant

      Many people have difficulty getting their Tcl code to work in an Xlate because they forget that xlateInVals and xlateOutVals are Tcl lists. One clue is that the names end with an “s”, implying multiple values.

      When you want  to use one of the incoming values you must select it from the LIST of input values in xlateInVals. When you are building your list of output values you must build xlateOutVals accordingly. This holds true even if there is only a single value in the list.

      Unless you want to make a copy of the entire list, do NOT use:

      Code:

      set ex $xlateInVals


      To get the first element of the list, even if it is the only element in the list, use:

      Code:

      set ex [lindex $xlateInVals 0]


      To get the second element of the list use:

      Code:

      set wy [lindex $xlateInVals 1]


      To get all the individual elements of the list at the same time in a single statement, you could use:

      Code:

      lassign $xlateInVals ex wy

      Why are xlateInVals and xlateOutVals lists? Because they can hold multiple values. If you have multiple source addresses in the Source side of an Xlate COPY statement, each of those addresses corresponds to a list element in xlateInVals. You can also have multiple addresses in the Destination side of that COPY statement. Each list element of xlateOutVals corresponds to one of the destination addresses. There are many ways to build lists. Note the quotes and the space between the two

    • items:

      Code:

      set xlateOutVals “[list $ex] [list $wy]”

      Another way to build xlateOutVals could be

      Code:

      set xlateOutVals {}
      lappend xlateOutVals $ex
      lappend xlateOutVals $wy

      Both

    • and [lappend] deal with maintaining the internal structure of Tcl lists, inserting whitespace and curly braces where they are required. If you treat lists appropriately, you don’t need to worry about the braces and whitespace, but if you don
    Viewing 1 reply thread
    Viewing 1 reply thread
    • The forum ‘Cloverleaf’ is closed to new topics and replies.