Re: The best way to copy a list?

Liste des GroupesRevenir à cl tcl 
Sujet : Re: The best way to copy a list?
De : auriocus (at) *nospam* gmx.de (Christian Gollwitzer)
Groupes : comp.lang.tcl
Date : 18. Jun 2025, 20:47:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102v547$3alce$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
Am 18.06.25 um 13:59 schrieb Mark Summerfield:
I'm coming to Tcl from Python & Go. In Python saying `a = [1, 2, 3]` and
then `b = a` makes `b` a _reference_ to `a` rather than an independent
variable. Now I realise that Tcl doesn't do it that way and that `set a
$b` works fine.
I suspected something like this, when reading your question. In Python terms, Tcl has only immutable values. Whereas in Python, the outcome of a[2] = 'x' depends on what exact type this "a" thing is, in Tcl it is either impossible or it creates a copy on write (lset).
This is part of the bigger "EIAS" concept ("everything is a string") which also means that values can be type-casted automatically - however, in good practice Tcl, you try to stick with a type nonetheless.
Christian

Date Sujet#  Auteur
18 Jun 25 * The best way to copy a list?8Mark Summerfield
18 Jun 25 +- Re: The best way to copy a list?1Harald Oehlmann
18 Jun 25 `* Re: The best way to copy a list?6Ashok
18 Jun 25  `* Re: The best way to copy a list?5Mark Summerfield
18 Jun 25   +- Re: The best way to copy a list?1Harald Oehlmann
18 Jun 25   +* Re: The best way to copy a list?2Colin Macleod
19 Jun 25   i`- Re: The best way to copy a list?1et99
18 Jun 25   `- Re: The best way to copy a list?1Christian Gollwitzer

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal