🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Why space cannot exist in array element index?

User: "Altair Forum User"
Altair Employee
Updated by Altair Forum User

Hi all, how to understand the following error?

 

set city(Guang zhou) 'Guangdong'     

wrong # args: should be 'set varName ?newValue?'

 

set city(Guang\ zhou) 'Guangdong'

Guangdong

 

2018-12-23_215116.png.fd8b6914dcd9e0e877773b8ed8d67746.png

 

Why space cannot exist in array element index?

 

Roy

Find more posts tagged with

Sort by:
1 - 5 of 51
    User: "tinh"
    Altair Community Member
    Updated by tinh

    Array names (also variable name, proc name) must be one word

    As tcl definition, string between 2 spaces is a word, or between 2 quotes or 2 braces

    \  is a way to concate special characters to a word, so 

    Guang\ zhou

    Is same as

    'Guang zhou'

    and same as

    {Guang zhou}

    is a word.

    but 

    Guang zhou

    are 2 words

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Array names (also variable name, proc name) must be one word

    As tcl definition, string between 2 spaces is a word, or between 2 quotes or 2 braces

    \  is a way to concate special characters to a word, so 

    Guang\ zhou

    Is same as

    'Guang zhou'

    and same as

    {Guang zhou}

    is a word.

    but 

    Guang zhou

    are 2 words

    Hi @tinh

    I try to use 'Guang zhou' or {Guang zhou}, the same error. However when using Guang,zhou, it is ok. How to understand?

     2018-12-24_105304.png.c9307cae19e85d8b4d83ad2dcf365a72.png

     

    Roy

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Maybe :

    set 'city(Guang zhou)' GuangZhou

     

    so 'city(Guang zhou)' is a variable name, it is one word

    array names ok to have multiple words 

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Maybe :

    set 'city(Guang zhou)' GuangZhou

     

    so 'city(Guang zhou)' is a variable name, it is one word

    array names ok to have multiple words ï»¿

    Hi @tinh

    I have tried your suggestion. 

    set 'city(Guang zhou)' 'Guangdong'     it is ok.

    How to understand why the previous statements were wrong? 

    2018-12-24_105304.png.00ca2d4ea5bd578a819f01a91e59f703.png

     

    Roy

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Just understand as whatever you want.

    If you can't, you don't need it to learn tcl, simply neglect all spaces.