Split string repeat Tcl
up vote
0
down vote
favorite
I am a fresh learner of Tcl and I faced an issue of understanding this whole concept:
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
columns is a variable with value 6;
How the split will be and which is my whole string?
Thank you all
string tcl
add a comment |
up vote
0
down vote
favorite
I am a fresh learner of Tcl and I faced an issue of understanding this whole concept:
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
columns is a variable with value 6;
How the split will be and which is my whole string?
Thank you all
string tcl
I'm not sure I understand what you are trying to ask, but have you tried running that piece of code?
– Jerry
Nov 10 at 14:53
What actual input data do you have? What output do you want?
– Donal Fellows
Nov 10 at 15:24
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am a fresh learner of Tcl and I faced an issue of understanding this whole concept:
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
columns is a variable with value 6;
How the split will be and which is my whole string?
Thank you all
string tcl
I am a fresh learner of Tcl and I faced an issue of understanding this whole concept:
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
columns is a variable with value 6;
How the split will be and which is my whole string?
Thank you all
string tcl
string tcl
edited Nov 10 at 15:22
Donal Fellows
101k15111171
101k15111171
asked Nov 10 at 14:32
Radostina Gencheva
11
11
I'm not sure I understand what you are trying to ask, but have you tried running that piece of code?
– Jerry
Nov 10 at 14:53
What actual input data do you have? What output do you want?
– Donal Fellows
Nov 10 at 15:24
add a comment |
I'm not sure I understand what you are trying to ask, but have you tried running that piece of code?
– Jerry
Nov 10 at 14:53
What actual input data do you have? What output do you want?
– Donal Fellows
Nov 10 at 15:24
I'm not sure I understand what you are trying to ask, but have you tried running that piece of code?
– Jerry
Nov 10 at 14:53
I'm not sure I understand what you are trying to ask, but have you tried running that piece of code?
– Jerry
Nov 10 at 14:53
What actual input data do you have? What output do you want?
– Donal Fellows
Nov 10 at 15:24
What actual input data do you have? What output do you want?
– Donal Fellows
Nov 10 at 15:24
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
You have to unpack Tcl commands from the inside out because the inner-most nested brackets are executed first.
columns
is a proc that, hopefully, returns an integer.- then
string repeat
repeats "-,-," that many times. - then the double quoted string adds a trailing
-
- then
split
should split that "-,-,-,...-" string on commas resulting in *a list of "2 * columns + 1" hyphens*.
Except:
- there is a missing space before the last comma in the split command
- the
set
command looks like:set varname value
(unless you're dealing with an object)
set <name of variable> [split "[string repeat "-,-," [columns]]-" ,]
# ...............................................................^
Demonstrating:
set columns 6
proc columns {} {return $::columns}
set result [split "[string repeat "-,-," [columns]]-" ,]
puts $result
puts [llength $result] ;# should be 13
- - - - - - - - - - - - -
13
You could achieve the same result with:
set result [lrepeat [expr {2 * [columns] + 1}] "-"]
Tcl is actually a very simple language. The entire syntax only has 12 rules: https://www.tcl.tk/man/tcl8.6/TclCmd/Tcl.htm
Seems sensible this way, thank you all for the help!
– Radostina Gencheva
Nov 11 at 17:55
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
You have to unpack Tcl commands from the inside out because the inner-most nested brackets are executed first.
columns
is a proc that, hopefully, returns an integer.- then
string repeat
repeats "-,-," that many times. - then the double quoted string adds a trailing
-
- then
split
should split that "-,-,-,...-" string on commas resulting in *a list of "2 * columns + 1" hyphens*.
Except:
- there is a missing space before the last comma in the split command
- the
set
command looks like:set varname value
(unless you're dealing with an object)
set <name of variable> [split "[string repeat "-,-," [columns]]-" ,]
# ...............................................................^
Demonstrating:
set columns 6
proc columns {} {return $::columns}
set result [split "[string repeat "-,-," [columns]]-" ,]
puts $result
puts [llength $result] ;# should be 13
- - - - - - - - - - - - -
13
You could achieve the same result with:
set result [lrepeat [expr {2 * [columns] + 1}] "-"]
Tcl is actually a very simple language. The entire syntax only has 12 rules: https://www.tcl.tk/man/tcl8.6/TclCmd/Tcl.htm
Seems sensible this way, thank you all for the help!
– Radostina Gencheva
Nov 11 at 17:55
add a comment |
up vote
1
down vote
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
You have to unpack Tcl commands from the inside out because the inner-most nested brackets are executed first.
columns
is a proc that, hopefully, returns an integer.- then
string repeat
repeats "-,-," that many times. - then the double quoted string adds a trailing
-
- then
split
should split that "-,-,-,...-" string on commas resulting in *a list of "2 * columns + 1" hyphens*.
Except:
- there is a missing space before the last comma in the split command
- the
set
command looks like:set varname value
(unless you're dealing with an object)
set <name of variable> [split "[string repeat "-,-," [columns]]-" ,]
# ...............................................................^
Demonstrating:
set columns 6
proc columns {} {return $::columns}
set result [split "[string repeat "-,-," [columns]]-" ,]
puts $result
puts [llength $result] ;# should be 13
- - - - - - - - - - - - -
13
You could achieve the same result with:
set result [lrepeat [expr {2 * [columns] + 1}] "-"]
Tcl is actually a very simple language. The entire syntax only has 12 rules: https://www.tcl.tk/man/tcl8.6/TclCmd/Tcl.htm
Seems sensible this way, thank you all for the help!
– Radostina Gencheva
Nov 11 at 17:55
add a comment |
up vote
1
down vote
up vote
1
down vote
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
You have to unpack Tcl commands from the inside out because the inner-most nested brackets are executed first.
columns
is a proc that, hopefully, returns an integer.- then
string repeat
repeats "-,-," that many times. - then the double quoted string adds a trailing
-
- then
split
should split that "-,-,-,...-" string on commas resulting in *a list of "2 * columns + 1" hyphens*.
Except:
- there is a missing space before the last comma in the split command
- the
set
command looks like:set varname value
(unless you're dealing with an object)
set <name of variable> [split "[string repeat "-,-," [columns]]-" ,]
# ...............................................................^
Demonstrating:
set columns 6
proc columns {} {return $::columns}
set result [split "[string repeat "-,-," [columns]]-" ,]
puts $result
puts [llength $result] ;# should be 13
- - - - - - - - - - - - -
13
You could achieve the same result with:
set result [lrepeat [expr {2 * [columns] + 1}] "-"]
Tcl is actually a very simple language. The entire syntax only has 12 rules: https://www.tcl.tk/man/tcl8.6/TclCmd/Tcl.htm
<name of variable> set [split "[string repeat "-,-," [columns]]-",]
You have to unpack Tcl commands from the inside out because the inner-most nested brackets are executed first.
columns
is a proc that, hopefully, returns an integer.- then
string repeat
repeats "-,-," that many times. - then the double quoted string adds a trailing
-
- then
split
should split that "-,-,-,...-" string on commas resulting in *a list of "2 * columns + 1" hyphens*.
Except:
- there is a missing space before the last comma in the split command
- the
set
command looks like:set varname value
(unless you're dealing with an object)
set <name of variable> [split "[string repeat "-,-," [columns]]-" ,]
# ...............................................................^
Demonstrating:
set columns 6
proc columns {} {return $::columns}
set result [split "[string repeat "-,-," [columns]]-" ,]
puts $result
puts [llength $result] ;# should be 13
- - - - - - - - - - - - -
13
You could achieve the same result with:
set result [lrepeat [expr {2 * [columns] + 1}] "-"]
Tcl is actually a very simple language. The entire syntax only has 12 rules: https://www.tcl.tk/man/tcl8.6/TclCmd/Tcl.htm
edited Nov 10 at 15:45
answered Nov 10 at 15:39
glenn jackman
164k26139233
164k26139233
Seems sensible this way, thank you all for the help!
– Radostina Gencheva
Nov 11 at 17:55
add a comment |
Seems sensible this way, thank you all for the help!
– Radostina Gencheva
Nov 11 at 17:55
Seems sensible this way, thank you all for the help!
– Radostina Gencheva
Nov 11 at 17:55
Seems sensible this way, thank you all for the help!
– Radostina Gencheva
Nov 11 at 17:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239964%2fsplit-string-repeat-tcl%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm not sure I understand what you are trying to ask, but have you tried running that piece of code?
– Jerry
Nov 10 at 14:53
What actual input data do you have? What output do you want?
– Donal Fellows
Nov 10 at 15:24