Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Rich Newsgroups: comp.lang.tcl Subject: Re: Array get element with default (no error if not exist) Date: Sun, 18 Aug 2024 16:43:41 -0000 (UTC) Organization: A noiseless patient Spider Lines: 15 Message-ID: References: <962f50d6039d29a1bcdd98d8931988a3@www.novabbs.com> <850513f1dcb6a0714bffa99c137f69f9@www.novabbs.com> Injection-Date: Sun, 18 Aug 2024 18:43:41 +0200 (CEST) Injection-Info: dont-email.me; posting-host="27a8b87db7433b5fa1dd735d9d0e6b28"; logging-data="2587133"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Puax/xCEEw78HnKCaQ6Qn" User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64)) Cancel-Lock: sha1:197VsDzE5mpmNHr2PCiWQAzhpP0= Bytes: 1758 RodionGork wrote: > Thank you, this definitely makes sense! > > I remember about issue with passing/returning array in functions. By the > way I still am not sure why it works with global for example... if they > are actually different variables, every key-pair :) e.g. like here: > > https://github.com/RodionGork/languages-benchmark/blob/main/02-primes/primes_a.tcl#L7 Because the [global] command works with names of variables, not the actual variables. It links the global variable with the given name, to a local variable of the same name, inside the proc. If the global name references an array, then the new local name inside the proc references the same array.