It would be mutable if it allowed something like this:
> a = 5
> a.add(1)
> print a
6
Note that numbers are immutable in most languages anyway. Arrays, hashmaps, and sometimes strings are the data types that are frequently mutable.It would be mutable if it allowed something like this:
> a = 5
> a.add(1)
> print a
6
Note that numbers are immutable in most languages anyway. Arrays, hashmaps, and sometimes strings are the data types that are frequently mutable.> 3 = 5
> print 3
5
The end
But given that it's not an object oriented language, how could any variable be mutable given your example/definition?
How could you mutate a variable in a way that this language disallows?
I presume something like this:
array a = [1, 2, 3]
a.append(4)
Names are mutable, but the values they point to are not.> Arrays and the elements of arrays are also immutable
I guess the docs need a bit of rewording. Forcing a deep-copy on variable assignment does not mean the variable itself is immutable.
https://www.amazon.com/Purely-Functional-Structures-Chris-Ok...
> Chaos language is not object-oriented. So everything is done by functions and data types.
a[0] = 1
Would be a better example. Appending to an array could involve creating a new array and reassigning it to ‘a’. function add(x, y) {
return x + y
}
a = 5
add(a, 1)
print(a)
A language printing 6 is pass by reference. A language printing 5 is pass by value.
Both would print 6 for this code a = add(a, 1)
print(a)
However a language like Erlang would end with an error when trying to reassign a new value to a. function add(x, y) {
x = x + y
return x
}