[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Are variables immutable?
- From: Lars Müller <appgurulars@...>
- Date: Wed, 25 May 2022 18:12:59 +0200
I phrased this poorly in my last sentence. What I'm trying to say is
that assigning a value is different from mutating e.g. a table. Lua
provides no way to mutate strings; you can't do str[idx] = something to
replace characters for instance.
On 25.05.22 18:06, Lars Müller wrote:
You're not changing the string "blah", you're changing the variable
myName (which is actually an entry in the global table). You can do a =
1; a = 2, overwriting a, because variables (both local and global) are
mutable in Lua (unless you use <const>), however this won't change 1 to
suddenly be 2. It works the same with strings - there is no way to
change part of a string, changing the contents of all variables holding
the string. Try e.g. a = "str" and b = "str", then overwrite a =
"different str" - b hasn't changed, because strings are immutable.
On 25.05.22 18:02, Duke Normandin wrote:
On Wed, 25 May 2022 16:48:08 +0200
Lars Müller <email@example.com> wrote:
It doesn't say "Lua variables are immutable", /it says that
strings are immutable like in Python/, which is the case - there
is no way to change the value of a string, you can only create
On 25.05.22 16:45, Duke Normandin wrote:
Lua noob here! Reading Lua primer at learnxinyminures.com to
start off with.
It says that Lua variables are immutable like in Python.
However, in the Lua REPL, I can change any value I set. Maybe I
should be reading a more recent tutorial? TIA ...
My mistake! However I set myName = 'blah' which is a string!
Correct? I can then say myName = 'blah-blau' and no error message
I'm missing something!