Undocumented Tcl 8.5 Issue

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Undocumented Tcl 8.5 Issue

  • Creator
    Topic
  • #54286
    Charlie Bursell
    Participant

      As most know Cloverleaf 6.0+ uses Tcl 8.5 while previous versions used Tcl 8.4.

      For years one of my “Soapbox” issues has been to treat lists as lists and strings as strings.  Tcl 8.5 makes that even more important.

      The lrange command will return a *LIST* though some treat it as a string

      In Tcl 8.4 you see the following:

      tcl>set lst

        A # B

        tcl>lrange $lst 1 1

        #

        However in Tcl 8.5+ it becomes:

        tcl>set lst

        A # B

        tcl>lrange $lst 1 1

        {#}

        If you attempt to do commands like regexp, string equal, etc against the results it will give you different results.  Note that {*} is a legitimate list with one value.  This quoting seems to occur with special characters

        If you really want to treat the results as a string, first convert to string:

        regexp — {#} [lindex [lrange $lst 1 1] 0]  OR

        regexp — {#} [join [lrange $lst 1 1]]

        You may have to modify 8..4 scripts if this applies.

    Viewing 2 reply threads
    • Author
      Replies
      • #80871
        Elisha Gould
        Participant

          The brackets around the result make sense as it is a list of items being returned. lrange is normally used to grab more than one items and is iterated through using foreach, lindex, join, etc.

          If you need only one item as text, lindex should be used and will return it as ‘#’ ie

          Code:

          tcl>set lst [list A # B]
          A # B
          tcl>lindex $lst 1
          #

        • #80872
          Charlie Bursell
          Participant

            You missed the point Elisha.  I used a single element as an example to show the differences between 8.4 and 8.5 when it comes to lists

          • #80873
            Elisha Gould
            Participant

              Sorry wasn’t meaning to have a go at you, I was trying to elaborate and extend a little on the correct way to handle lists.

              I understand the point you were making to be wary of the difference and that just because it behaves one way in a version doesn’t mean that it should be used in that manor.

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