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.
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.
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.
triggers rule 7 identification which allows for the (") within the command. Substitutions are made in place during the scan.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 '['
% 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
I hope this helps.
On Saturday, March 19, 2022 at 2:43:27 PM UTC-7, briang wrote:' triggers rule 7 identification which allows for the (") within the command. Substitutions are made in place during the scan.
On Friday, March 18, 2022 at 6:42:13 PM UTC-7, jtyler wrote:
On 3/18/2022 6:34 PM, jtyler wrote: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 '[
I just recently noticed some code that I didn't think worked based onCommand substitution is actually rule 7. And I also imagine that \"
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.
doesn't count as the next double-quote character too.
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
Substitutions are made in place during the scan.
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 "
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (0 / 16) |
| Uptime: | 168:43:35 |
| Calls: | 12,097 |
| Calls today: | 5 |
| Files: | 15,003 |
| Messages: | 6,517,823 |