• Why do I get accolades

    From Cecil Westerhof@21:1/5 to All on Thu Sep 29 00:00:15 2022
    When I use:
    puts [format "%s (%s)" ${package} ${blockingPckg}]

    I get:
    pyppmd (py7zr)

    When I use:
    lappend manual ${package}
    puts ${manual}

    I get:
    pyppmd

    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]
    puts ${manual}

    I get:
    {pyppmd (py7zr)}


    What could be happening here? I would expect:
    pyppmd (py7zr)

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Cecil Westerhof on Thu Sep 29 00:42:54 2022
    Cecil Westerhof <Cecil@decebal.nl> writes:

    When I use:
    puts [format "%s (%s)" ${package} ${blockingPckg}]

    I get:
    pyppmd (py7zr)

    When I use:
    lappend manual ${package}
    puts ${manual}

    I get:
    pyppmd

    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]

    It works when I use:
    append manual [format "%s (%s) " ${package} ${blockingPckg}]

    But I am still interested in what is happening.


    puts ${manual}

    I get:
    {pyppmd (py7zr)}


    What could be happening here? I would expect:
    pyppmd (py7zr)

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Cecil Westerhof on Wed Sep 28 20:43:18 2022
    On 9/28/22 6:00 PM, Cecil Westerhof wrote:
    When I use:
    puts [format "%s (%s)" ${package} ${blockingPckg}]

    I get:
    pyppmd (py7zr)

    When I use:
    lappend manual ${package}
    puts ${manual}

    I get:
    pyppmd

    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]
    puts ${manual}

    I get:
    {pyppmd (py7zr)}


    What could be happening here? I would expect:
    pyppmd (py7zr)


    It is because of the space: Your manual variable is a list, which
    contains an element with characters that require special handling in
    Tcl, which here happens to be the space character. Space is also the
    default delimiter that [puts] uses when printing lists. In this case,
    it would cause a confusion as to whether what it printed was two
    separate elements, or a single element with spaces in it.

    Try eliminating the space by using "%s(%s)" as the format or try using
    [join $manual] before printing it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Thu Sep 29 00:50:15 2022
    Try these:

    puts [list "a c"]

    should show: {a c}

    and

    puts [list "abc"]

    should show: abc

    In both cases puts displays the string representation of a list
    with a single entry which is a 3 character string.
    The {a c} is braced so the string "a c" will be parsed as a single list entry
    if string is interpreted as a list.

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Cecil Westerhof on Wed Sep 28 20:45:37 2022
    On 9/28/22 6:42 PM, Cecil Westerhof wrote:

    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]

    It works when I use:
    append manual [format "%s (%s) " ${package} ${blockingPckg}]

    But I am still interested in what is happening.



    [lappend] and [append] are two very different commands, operating on
    lists vs. strings. Hopefully my previous message explained the why here.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Cecil Westerhof on Thu Sep 29 01:49:24 2022
    Cecil Westerhof <Cecil@decebal.nl> wrote:
    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]
    puts ${manual}

    I get:
    {pyppmd (py7zr)}


    What could be happening here? I would expect:
    pyppmd (py7zr)

    Not from Tcl you shouldn't.

    When you "puts" a list, Tcl outputs a string encoded such that it can
    be converted back into the same list structure again later.

    The { and } appear because space is normally a list element separator,
    but when the separator appears in the value of an element, it is
    'escaped' by surrounding the value with { }.

    It is the same reasoning as to why CSV elements, themselves containing
    commas as data, get surrounded by double quote characters.


    Note this part of the 'list' manpage description:

    Braces and backslashes get added as necessary, so that the
    lindex command may be used on the result to re-extract the
    original arguments, ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Thu Sep 29 08:56:31 2022
    Am 29.09.2022 um 00:00 schrieb Cecil Westerhof:
    When I use:
    puts [format "%s (%s)" ${package} ${blockingPckg}]

    I get:
    pyppmd (py7zr)

    When I use:
    lappend manual ${package}
    puts ${manual}

    I get:
    pyppmd

    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]
    puts ${manual}

    I get:
    {pyppmd (py7zr)}

    lappend is a list append and transforms each parameter to a valid list
    element. As the string contains a space, curly braces aree added.
    To make it simpler, you may write:
    lappend manual "pyppmd (py7zr)"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Harald Oehlmann on Thu Sep 29 10:47:58 2022
    Harald Oehlmann <wortkarg3@yahoo.com> writes:

    Am 29.09.2022 um 00:00 schrieb Cecil Westerhof:
    When I use:
    puts [format "%s (%s)" ${package} ${blockingPckg}]
    I get:
    pyppmd (py7zr)
    When I use:
    lappend manual ${package}
    puts ${manual}
    I get:
    pyppmd
    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]
    puts ${manual}
    I get:
    {pyppmd (py7zr)}

    lappend is a list append and transforms each parameter to a valid list element. As the string contains a space, curly braces aree added.
    To make it simpler, you may write:
    lappend manual "pyppmd (py7zr)"

    I do not think that that will work, because the format is giving that
    string.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to saitology9@gmail.com on Thu Sep 29 10:46:00 2022
    saitology9 <saitology9@gmail.com> writes:

    On 9/28/22 6:00 PM, Cecil Westerhof wrote:
    When I use:
    puts [format "%s (%s)" ${package} ${blockingPckg}]
    I get:
    pyppmd (py7zr)
    When I use:
    lappend manual ${package}
    puts ${manual}
    I get:
    pyppmd
    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]
    puts ${manual}
    I get:
    {pyppmd (py7zr)}

    What could be happening here? I would expect:
    pyppmd (py7zr)


    It is because of the space: Your manual variable is a list, which
    contains an element with characters that require special handling in
    Tcl, which here happens to be the space character. Space is also the
    default delimiter that [puts] uses when printing lists. In this case,
    it would cause a confusion as to whether what it printed was two
    separate elements, or a single element with spaces in it.

    Try eliminating the space by using "%s(%s)" as the format or try using
    [join $manual] before printing it.

    I use tclsh not enough. I should have know this. :'-(

    First I only saved the package name, now I add the blocking package. I
    should have used append instead of lappend from day one, but in the
    original case the result was the same. So it did not have
    consequences.
    But it was still a bug in my opinion: I needed a string, so no reason
    to work with a list.


    By the way I use a tclsh script to keep my python pip up to date. :-D

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Cecil Westerhof on Thu Sep 29 10:56:54 2022
    Cecil Westerhof <Cecil@decebal.nl> writes:

    append manual [format "%s (%s) " ${package} ${blockingPckg}]

    And I make thing needlessly difficult again. I should just use:
    append manual "${package} (${blockingPackage}) "

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Cecil Westerhof on Thu Sep 29 12:41:24 2022
    Cecil Westerhof <Cecil@decebal.nl> wrote:
    Harald Oehlmann <wortkarg3@yahoo.com> writes:

    Am 29.09.2022 um 00:00 schrieb Cecil Westerhof:
    When I use:
    puts [format "%s (%s)" ${package} ${blockingPckg}]
    I get:
    pyppmd (py7zr)
    When I use:
    lappend manual ${package}
    puts ${manual}
    I get:
    pyppmd
    But when I use:
    lappend manual [format "%s (%s)" ${package} ${blockingPckg}]
    puts ${manual}
    I get:
    {pyppmd (py7zr)}

    lappend is a list append and transforms each parameter to a valid list
    element. As the string contains a space, curly braces aree added.
    To make it simpler, you may write:
    lappend manual "pyppmd (py7zr)"

    I do not think that that will work, because the format is giving that
    string.

    Harald's version will produce the same output as your format:

    $ rlwrap tclsh
    % lappend manual "pyppmd (py7zr)"
    {pyppmd (py7zr)}
    % puts $manual
    {pyppmd (py7zr)}
    %

    You get the curly braces because of the space inside element zero, not
    because you used format to generate the string that became element
    zero's content.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Cecil Westerhof on Thu Sep 29 12:34:25 2022
    Cecil Westerhof <Cecil@decebal.nl> wrote:
    I use tclsh not enough. I should have know this. :'-(

    First I only saved the package name, now I add the blocking package.
    I should have used append instead of lappend from day one, but in the original case the result was the same. So it did not have
    consequences.

    But it was still a bug in my opinion: I needed a string, so no reason
    to work with a list.

    Yes, and it is a "latent, hiding, data dependent bug". Using 'lists'
    when you really want a plain string can most often seem to work fine,
    because the basic, unescaped, string rep often looks identical to just
    a plain string.

    Then, months or years later, your code consumes a data value containing
    a list 'meta-character' and the list escaping code does what you asked,
    and escapes the string representation of the list values, and you have
    either weird data being produced, or you have an actual exception error situation.

    It is in general best to never use list operators on plain strings, and
    to never use string operators on lists. It is possible to do so
    safely, but doing so is an 'advanced technique' and the programmer has
    to fully understand the ramifications of what they are asking the
    runtime to perform.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Cecil Westerhof on Thu Sep 29 12:29:10 2022
    Cecil Westerhof <Cecil@decebal.nl> wrote:
    Cecil Westerhof <Cecil@decebal.nl> writes:

    append manual [format "%s (%s) " ${package} ${blockingPckg}]

    And I make thing needlessly difficult again. I should just use:
    append manual "${package} (${blockingPackage}) "

    For plain strings, yes.

    If you /want/ formatting (i.e. fixed width columns, or real's to a
    specific decimal place, etc.) then of course use format.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)