• Re: rule 4 on double quotes

    From jtyler@21:1/5 to jtyler on Fri Mar 18 18:42:08 2022
    On 3/18/2022 6:34 PM, jtyler wrote:
    I just recently noticed some code that I didn't think worked based on
    the wording of Rule 4, which begins:

    If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character.

    But this code is valid:

    % set val " [string repeat "a " 5]x "
     a a a a a x
    % puts =$val=
    = a a a a a x =

    Up till now, I would have coded the "a " as {a } since I thought the
    quote before the a was the *next double-quote character*.

    After reading rule 8 yet again (must have read this 100's of times
    before) I can see how the "recursive" tcl interpreter call would
    completely replace the [string repeat...] with the command result, and
    it's scanning pointer (or index) is somehow also adjusted so the outer interpreter picks up again after the close bracket so as not to rescan
    what was just substituted.

    Wow, that's difficult to put into English :)

    But... Doesn't this mean the manual is incorrect? Shouldn't it say in
    rule 4 something like,

    If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character not recursively replaced
    by a command substitution.

    Either that, or perhaps rule 8 should mention this.




    Command substitution is actually rule 7. And I also imagine that \"
    doesn't count as the next double-quote character too.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jtyler@21:1/5 to All on Fri Mar 18 18:34:50 2022
    I just recently noticed some code that I didn't think worked based on
    the wording of Rule 4, which begins:

    If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character.

    But this code is valid:

    % set val " [string repeat "a " 5]x "
    a a a a a x
    % puts =$val=
    = a a a a a x =

    Up till now, I would have coded the "a " as {a } since I thought the
    quote before the a was the *next double-quote character*.

    After reading rule 8 yet again (must have read this 100's of times
    before) I can see how the "recursive" tcl interpreter call would
    completely replace the [string repeat...] with the command result, and
    it's scanning pointer (or index) is somehow also adjusted so the outer interpreter picks up again after the close bracket so as not to rescan
    what was just substituted.

    Wow, that's difficult to put into English :)

    But... Doesn't this mean the manual is incorrect? Shouldn't it say in
    rule 4 something like,

    If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character not recursively replaced
    by a command substitution.

    Either that, or perhaps rule 8 should mention this.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From briang@21:1/5 to jtyler on Sat Mar 19 14:43:24 2022
    On Friday, March 18, 2022 at 6:42:13 PM UTC-7, jtyler wrote:
    On 3/18/2022 6:34 PM, jtyler wrote:
    I just recently noticed some code that I didn't think worked based on
    the wording of Rule 4, which begins:

    If the first character of a word is double-quote (“"”) then the word is
    terminated by the next double-quote character.

    But this code is valid:

    % set val " [string repeat "a " 5]x "
    a a a a a x
    % puts =$val=
    = a a a a a x =

    Up till now, I would have coded the "a " as {a } since I thought the
    quote before the a was the *next double-quote character*.

    After reading rule 8 yet again (must have read this 100's of times
    before) I can see how the "recursive" tcl interpreter call would completely replace the [string repeat...] with the command result, and it's scanning pointer (or index) is somehow also adjusted so the outer interpreter picks up again after the close bracket so as not to rescan what was just substituted.

    Wow, that's difficult to put into English :)

    But... Doesn't this mean the manual is incorrect? Shouldn't it say in
    rule 4 something like,

    If the first character of a word is double-quote (“"”) then the word is
    terminated by the next double-quote character not recursively replaced
    by a command substitution.

    Either that, or perhaps rule 8 should mention this.



    Command substitution is actually rule 7. And I also imagine that \"
    doesn't count as the next double-quote character too.

    Rule 4 states that command substitution is performed within the quoted word, which requires identifying the command substitution beforehand. The unstated fact is that the input is scanned once, no going back and rescanning afterwards. This means the '['
    triggers rule 7 identification which allows for the (") within the command. Substitutions are made in place during the scan.

    % unset a
    can't unset "a": no such variable
    % set b "Hello to [set a hello] which is also known as $a"
    Hello to hello which is also known as hello
    % unset x
    can't unset "x": no such variable
    % set c "Hello to $x, which is also known as [set x wrongly]"
    can't read "x": no such variable
    % set x
    can't read "x": no such variable

    I hope this helps.
    -Brian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From briang@21:1/5 to briang on Sat Mar 19 14:59:22 2022
    On Saturday, March 19, 2022 at 2:43:27 PM UTC-7, briang wrote:
    On Friday, March 18, 2022 at 6:42:13 PM UTC-7, jtyler wrote:
    On 3/18/2022 6:34 PM, jtyler wrote:
    I just recently noticed some code that I didn't think worked based on the wording of Rule 4, which begins:

    If the first character of a word is double-quote (“"”) then the word is
    terminated by the next double-quote character.

    But this code is valid:

    % set val " [string repeat "a " 5]x "
    a a a a a x
    % puts =$val=
    = a a a a a x =

    Up till now, I would have coded the "a " as {a } since I thought the quote before the a was the *next double-quote character*.

    After reading rule 8 yet again (must have read this 100's of times before) I can see how the "recursive" tcl interpreter call would completely replace the [string repeat...] with the command result, and it's scanning pointer (or index) is somehow also adjusted so the outer interpreter picks up again after the close bracket so as not to rescan what was just substituted.

    Wow, that's difficult to put into English :)

    But... Doesn't this mean the manual is incorrect? Shouldn't it say in rule 4 something like,

    If the first character of a word is double-quote (“"”) then the word is
    terminated by the next double-quote character not recursively replaced by a command substitution.

    Either that, or perhaps rule 8 should mention this.



    Command substitution is actually rule 7. And I also imagine that \" doesn't count as the next double-quote character too.
    Rule 4 states that command substitution is performed within the quoted word, which requires identifying the command substitution beforehand. The unstated fact is that the input is scanned once, no going back and rescanning afterwards. This means the '['
    triggers rule 7 identification which allows for the (") within the command. Substitutions are made in place during the scan.

    Correction, the unstated fact is indeed stated, see Rule 11!
    My bad.


    % unset a
    can't unset "a": no such variable
    % set b "Hello to [set a hello] which is also known as $a"
    Hello to hello which is also known as hello
    % unset x
    can't unset "x": no such variable
    % set c "Hello to $x, which is also known as [set x wrongly]"
    can't read "x": no such variable
    % set x
    can't read "x": no such variable

    I hope this helps.
    -Brian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Siri Cruise@21:1/5 to All on Sat Mar 19 16:10:24 2022
    I hope this helps.

    Doctor! Doctor! It hurts when I do this.

    Then stop doing that.

    --
    :-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
    'I desire mercy, not sacrifice.' /|\ Discordia: not just a religion but also a parody. This post / \
    I am an Andrea Doria sockpuppet. insults Islam. Mohammed

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jtyler@21:1/5 to briang on Mon Mar 21 12:46:48 2022
    On 3/19/2022 2:59 PM, briang wrote:
    On Saturday, March 19, 2022 at 2:43:27 PM UTC-7, briang wrote:
    On Friday, March 18, 2022 at 6:42:13 PM UTC-7, jtyler wrote:
    On 3/18/2022 6:34 PM, jtyler wrote:
    I just recently noticed some code that I didn't think worked based on
    the wording of Rule 4, which begins:

    If the first character of a word is double-quote (“"”) then the word is
    terminated by the next double-quote character.

    But this code is valid:

    % set val " [string repeat "a " 5]x "
    a a a a a x
    % puts =$val=
    = a a a a a x =

    Up till now, I would have coded the "a " as {a } since I thought the
    quote before the a was the *next double-quote character*.

    After reading rule 8 yet again (must have read this 100's of times
    before) I can see how the "recursive" tcl interpreter call would
    completely replace the [string repeat...] with the command result, and >>>> it's scanning pointer (or index) is somehow also adjusted so the outer >>>> interpreter picks up again after the close bracket so as not to rescan >>>> what was just substituted.

    Wow, that's difficult to put into English :)

    But... Doesn't this mean the manual is incorrect? Shouldn't it say in
    rule 4 something like,

    If the first character of a word is double-quote (“"”) then the word is
    terminated by the next double-quote character not recursively replaced >>>> by a command substitution.

    Either that, or perhaps rule 8 should mention this.



    Command substitution is actually rule 7. And I also imagine that \"
    doesn't count as the next double-quote character too.
    Rule 4 states that command substitution is performed within the quoted word, which requires identifying the command substitution beforehand. The unstated fact is that the input is scanned once, no going back and rescanning afterwards. This means the '[
    ' triggers rule 7 identification which allows for the (") within the command. Substitutions are made in place during the scan.

    Correction, the unstated fact is indeed stated, see Rule 11!
    My bad.


    % unset a
    can't unset "a": no such variable
    % set b "Hello to [set a hello] which is also known as $a"
    Hello to hello which is also known as hello
    % unset x
    can't unset "x": no such variable
    % set c "Hello to $x, which is also known as [set x wrongly]"
    can't read "x": no such variable
    % set x
    can't read "x": no such variable

    I hope this helps.
    -Brian


    Yes, if one reads all the rules, one can probably reason in a courtroom
    that rule 11 is sufficient to explain that a command substitution inside
    of a word with double quotes on both ends can be completely processed as
    if it stood on its own. That's the recursive part.

    For a newcomer, I would think that it might be more clear with an
    example, and/or a slightly different wording. Documentation is often
    more difficult than writing code, but here's a wording I think might
    possibly make rule 4 more clear w/o the need to refer to other rules:


    If the first character of a word is double-quote (“"”) then the word is terminated by a *closing* double-quote character. Any following double
    quotes that are \ escaped, or are enclosed in a properly nested command substitution, are not closing quotes for the word. For example,


    set a "the next 2 quotes [set b "\"<- are both not a close quote for the
    first quote"] but is closed by this final one \" here ->"



    After 20 years of tcl coding, I was quite surprised when I saw this
    done. I often use quotes around bare words although not needed, in order
    to get my text editor to color the quoted strings and to make it clear
    what the intention is. This will make it easier to do so now.

    Thanks.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andreas Leitgeb@21:1/5 to briang on Thu Mar 31 18:35:40 2022
    briang <[email protected]> wrote:
    Substitutions are made in place during the scan.

    Well, I'd think they're only "arranged for" during the scan, because

    % eval {puts "fu[puts hello]bar}
    missing "

    doesn't print "hello" before noticing the missing "

    (and I also wouldn't expect byte-compilation within eval)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oleg Nemanov@21:1/5 to All on Tue Apr 26 07:44:01 2022
    четверг, 31 марта 2022 г. в 21:35:44 UTC+3, Andreas Leitgeb:
    briang <[email protected]> wrote:
    Substitutions are made in place during the scan.
    Well, I'd think they're only "arranged for" during the scan, because

    % eval {puts "fu[puts hello]bar}
    missing "

    doesn't print "hello" before noticing the missing "

    Doesn't this is due to the word splitting is done before the substitution?
    To see word boundaries we need to find the closing ".

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