Question

I am confused at "join" command, here is my code inside tclsh:

% lappend aaa 1
1
% lappend aaa 2
1 2
% lappend aaa {3 4}
1 2 {3 4}
% join $aaa
1 2 3 4

so the list aaa should have 3 elements: 1, 2 and {3 4}. Because "join" command should just concat all the elements together to form a string, then the return should be "1 2 {3 4}" because the list has just 3 elements. Why does join command break the 3rd element?

Était-ce utile?

La solution

It doesn't. The 3rd element is a string 3 4 -- the braces you see are not actually part of the string. You're joining with a space, so the space in the string is not visually different. An example:

% lappend aaa 1
1
% lappend aaa 2
1 2
% lappend aaa {3 4}
1 2 {3 4}
% lappend aaa 5
1 2 {3 4} 5
% join $aaa :
1:2:3 4:5
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top