• Re: Puts output multiple lines don't get aligned when using '\n\'.

    From Harald Oehlmann@21:1/5 to All on Thu Feb 24 08:06:05 2022
    Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:
    See my following test:

    ```
    werner@X10DAi-00:~$ tclsh
    tclsh8.6 [~] set a x
    x
    tclsh8.6 [~] set b y
    y
    tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
    %s" $a $b]
    x
    y
    ```

    As you can see, there is a leading space in the last output line. I want to get multi-line output for a very long variable list, with "\" as a continuation of the code logic row, and align the results.

    Any hints on this question?

    Regards,
    HZ

    A line continuation with "\" inserts implicitly a space:

    % puts "a\
    b"
    a b

    I hope hit the nail.

    Take care,
    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hongyi Zhao@21:1/5 to All on Wed Feb 23 23:00:24 2022
    See my following test:

    ```
    werner@X10DAi-00:~$ tclsh
    tclsh8.6 [~] set a x
    x
    tclsh8.6 [~] set b y
    y
    tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
    %s" $a $b]
    x
    y
    ```

    As you can see, there is a leading space in the last output line. I want to get multi-line output for a very long variable list, with "\" as a continuation of the code logic row, and align the results.

    Any hints on this question?

    Regards,
    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hongyi Zhao@21:1/5 to Harald Oehlmann on Wed Feb 23 23:29:02 2022
    On Thursday, February 24, 2022 at 3:17:31 PM UTC+8, Harald Oehlmann wrote:
    Am 24.02.2022 um 08:06 schrieb Harald Oehlmann:
    Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:
    See my following test:

    ```
    werner@X10DAi-00:~$ tclsh
    tclsh8.6 [~] set a x
    x
    tclsh8.6 [~] set b y
    y
    tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
    %s" $a $b]
    x
    y
    ```

    As you can see, there is a leading space in the last output line. I
    want to get multi-line output for a very long variable list, with "\"
    as a continuation of the code logic row, and align the results.

    Any hints on this question?

    Regards,
    HZ

    A line continuation with "\" inserts implicitly a space:

    % puts "a\
    b"
    a b

    I hope hit the nail.
    Sorry:
    I hope I hit the nail.

    The name of your computer is related to Christian Werner, Mr. Androwish?

    No, it comes from the name of "Werner Lemberg" [1], who inspired me into the world of Tex many years ago.

    BTW, who is "Christian Werner, Mr. Androwish"?

    [1] https://www.ctan.org/author/lemberg

    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Thu Feb 24 08:17:26 2022
    Am 24.02.2022 um 08:06 schrieb Harald Oehlmann:
    Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:
    See my following test:

    ```
    werner@X10DAi-00:~$ tclsh
    tclsh8.6 [~] set a x
    x
    tclsh8.6 [~] set b y
    y
    tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
    %s" $a $b]
    x
      y
    ```

    As you can see, there is a leading space in the last output line. I
    want to get multi-line output for a very long variable list, with "\"
    as a continuation of the code logic row, and align the results.

    Any hints on this question?

    Regards,
    HZ

    A line continuation with "\" inserts implicitly a space:

    % puts "a\
    b"
    a b

    I hope  hit the nail.
    Sorry:
    I hope I hit the nail.

    The name of your computer is related to Christian Werner, Mr. Androwish?

    Thanks,
    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hongyi Zhao@21:1/5 to Harald Oehlmann on Wed Feb 23 23:33:27 2022
    On Thursday, February 24, 2022 at 3:06:11 PM UTC+8, Harald Oehlmann wrote:
    Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:
    See my following test:

    ```
    werner@X10DAi-00:~$ tclsh
    tclsh8.6 [~] set a x
    x
    tclsh8.6 [~] set b y
    y
    tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
    %s" $a $b]
    x
    y
    ```

    As you can see, there is a leading space in the last output line. I want to get multi-line output for a very long variable list, with "\" as a continuation of the code logic row, and align the results.

    Any hints on this question?

    Regards,
    HZ

    A line continuation with "\" inserts implicitly a space:

    % puts "a\
    b"
    a b

    Then how to avoid this behavior for a long line cont'd with it?

    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Thu Feb 24 08:51:52 2022
    Am 24.02.22 um 08:33 schrieb Hongyi Zhao:
    On Thursday, February 24, 2022 at 3:06:11 PM UTC+8, Harald Oehlmann wrote:
    A line continuation with "\" inserts implicitly a space:

    % puts "a\
    b"
    a b

    Then how to avoid this behavior for a long line cont'd with it?

    You can't for line continuation, but for the problem of formatting some multi-line string there are different solutions.
    One is: Create a list instead with one elemnt for each line, then join
    with \n:

    set l [list "line 1 $a" \
    "line 2 $b" \
    "line 3"]
    # you can break the lines if you wish, but you can also put it on one line

    set l [list "line 1 $a" "line 2 $b" "line 3"]
    puts [join $l "\n"]


    Or you can use "string map" and substitute placeholders in a template
    like this:

    set template {line 1 @A@
    line 2 @B@
    line 3 AB @A@@B@}

    set vars [list @A@ $a @B@ $b]

    puts [string map $vars $template]


    The @A@ thing here is not special syntax, it is just any arbitrary
    string that does not appear anywhere else in the template.

    Or you could use subst, however, that substitutes all Tcl variables:

    set template {line 1 $a
    line 2 $b
    line 3 AB $a$b}

    puts [subst -nocommands $template]

    The -nocommands prevents subst from substituting bracketed commands in
    the template. It's the most simple, but you might reconsider if it is a security risk - depends on the use case.

    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Thu Feb 24 08:59:44 2022
    Am 24.02.2022 um 08:29 schrieb Hongyi Zhao:
    On Thursday, February 24, 2022 at 3:17:31 PM UTC+8, Harald Oehlmann wrote:
    Am 24.02.2022 um 08:06 schrieb Harald Oehlmann:
    Am 24.02.2022 um 08:00 schrieb Hongyi Zhao:
    See my following test:

    ```
    werner@X10DAi-00:~$ tclsh
    tclsh8.6 [~] set a x
    x
    tclsh8.6 [~] set b y
    y
    tclsh8.6 [~] puts -nonewline stderr [format "%s\n\
    %s" $a $b]
    x
    y
    ```

    As you can see, there is a leading space in the last output line. I
    want to get multi-line output for a very long variable list, with "\"
    as a continuation of the code logic row, and align the results.

    Any hints on this question?

    Regards,
    HZ

    A line continuation with "\" inserts implicitly a space:

    % puts "a\
    b"
    a b

    I hope hit the nail.
    Sorry:
    I hope I hit the nail.

    The name of your computer is related to Christian Werner, Mr. Androwish?

    No, it comes from the name of "Werner Lemberg" [1], who inspired me into the world of Tex many years ago.

    BTW, who is "Christian Werner, Mr. Androwish"?

    [1] https://www.ctan.org/author/lemberg

    HZ

    Christian Gollwitzer (auriocus) already answered technically.

    Christian Werner (the other Christian) has created Androwish and
    Undroidwish. Those are two advanced TCL distributions which run natively
    on many platforms including Android.
    You may look to his presentations on Youtube.

    Take care,
    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hongyi Zhao@21:1/5 to Christian Gollwitzer on Thu Feb 24 00:14:45 2022
    On Thursday, February 24, 2022 at 3:51:57 PM UTC+8, Christian Gollwitzer wrote:
    Am 24.02.22 um 08:33 schrieb Hongyi Zhao:
    On Thursday, February 24, 2022 at 3:06:11 PM UTC+8, Harald Oehlmann wrote:
    A line continuation with "\" inserts implicitly a space:

    % puts "a\
    b"
    a b

    Then how to avoid this behavior for a long line cont'd with it?
    You can't for line continuation, but for the problem of formatting some multi-line string there are different solutions.
    One is: Create a list instead with one elemnt for each line, then join
    with \n:

    set l [list "line 1 $a" \
    "line 2 $b" \
    "line 3"]

    I like this simple yet workable way. Thank you for your tips.

    # you can break the lines if you wish, but you can also put it on one line

    set l [list "line 1 $a" "line 2 $b" "line 3"]
    puts [join $l "\n"]


    Or you can use "string map" and substitute placeholders in a template
    like this:

    set template {line 1 @A@
    line 2 @B@
    line 3 AB @A@@B@}

    set vars [list @A@ $a @B@ $b]

    puts [string map $vars $template]


    The @A@ thing here is not special syntax, it is just any arbitrary
    string that does not appear anywhere else in the template.

    Or you could use subst, however, that substitutes all Tcl variables:

    set template {line 1 $a
    line 2 $b
    line 3 AB $a$b}

    puts [subst -nocommands $template]

    The -nocommands prevents subst from substituting bracketed commands in
    the template. It's the most simple, but you might reconsider if it is a security risk - depends on the use case.

    Christian

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