Questions tagged [mutable]

A mutable can be modified after it is created.

A mutable can be modified after it is created. It is a keyword in functional programming opposite to immutable.

Related tags:

1184 questions
0
votes
3 answers

Implementing a Number System in Java: Mutable vs. Immutable

I am implementing classes for rational numbers, but the problems and issues are essentially the same for complex numbers as well as other classes intended to be used in applications with a significant number of calculations performed on a given…
Ned
  • 937
  • 6
  • 10
0
votes
1 answer

Python Lists append mutable variable

Still new to programming/scripting, and this one's been bothering me. I have a function that searches through a list of names, comparing it to a template list of names, and when it finds a match, it places it in my final list in the correct order.…
CG7Son
  • 31
  • 3
0
votes
1 answer

Scala unable to change values in mutable Map[Char, Map[Int, Double]] with default values

All maps in this code are mutable maps due to the import statement earlier on in the full code. The nGramGetter.getNGrams(...) method call returns a Map[String, Int]. def train(files: Array[java.io.File]): Map[Char, Map[Int, Double]] = { val…
0
votes
2 answers

How to make a method that swaps mutable types? (Natural Numbers) Java

I don't know how the value of an object that is referring to a reference. I am not talking about integers by the way. I want to make this method. swapNN(NaturalNumber j, NaturalNumber n) I want the references of j and n to be swapped but I don't…
user2744298
  • 1
  • 1
  • 1
  • 3
0
votes
1 answer

Multiple references in separate lists; Python

I'm trying to basically create references to plot multiple relationships and store them in a list or possibly a dictionary. Basically: variable1 = 10 //in this case, 'ref' denotes that the variable should be a reference) listA = [variable1(ref),…
0
votes
4 answers

Any way to make a mutable object derived from an immutable object in C#?

I'm interested in making an immutable class that has properties that cannot be modified, and a mutable class that derives from it. These objects would be simple data objects representing database records, so they would have only immutable values…
Joe Enos
  • 39,478
  • 11
  • 80
  • 136
0
votes
2 answers

I need an object that is passed by value and mutable

I am new to C#, so bear with me. I have a problem in c# where I can't decide on whether I need a class or a struct. I'm creating a List of either the class or struct and adding elements to it. If I use a struct, then I can add an item, alter it, and…
Synaps3
  • 1,597
  • 2
  • 15
  • 23
0
votes
5 answers

Make a reference immutable?

class Some{ private int id; private String name; //getters and setters } class Check{ private Some[] someVals; //getters and setters } Assume I have populated values into the someVals in Check class void newMethod(){ Check checkPrev…
Dinesh Kumar
  • 2,838
  • 1
  • 16
  • 18
0
votes
3 answers

Temporary mutability of a member variable

Is it possible to have a member variable only be considered mutable for a given function/code block? e.g. class Foo() { int blah; void bar() const { blah = 5; // compiler error } void mutable_bar() const { blah = 5; // no compiler…
Brian
  • 2,499
  • 3
  • 24
  • 26
0
votes
1 answer

making an immutable type mutable (consts and boost)

I am working on a feature for a codebase that I cannot change (save for what I'm writing) and there are some types here: // Pointer to a mutable thingy typedef boost::shared_ptr MPtr; // Pointer to an immutable thingy typedef…
easythrees
  • 1,530
  • 3
  • 16
  • 43
0
votes
2 answers

What is the immutable version to de/reference array?

How to de/reference the 3 array variables in this code instead of using mutable values? The code below computes the Longest common subsequence (LCS) by diagonal traversing the m*n array. The arguments are 2 char arrays like so: So LCS method should…
0
votes
3 answers

Are Strings *really* immutable in Java?

Everyone knows that Java's String object is immutable which essentially means that if you take String object a and concatenate it with another String object, say b, a totally new String object is created instead of an inplace concatenation. However,…
Cemre Mengü
  • 18,062
  • 27
  • 111
  • 169
0
votes
1 answer

F# reading csv line by line asynchronously with mutable object

I've read a lot of posts here that help me a lot with my problem, but all my attempts did not bear fruit. Hear is my code: first function (Reading file for use line by line) let readLines filePath = System.IO.File.ReadLines(filePath) Second…
Anass
  • 73
  • 4
0
votes
2 answers

How do I accumulate results without using a mutable ArrayBuffer?

The code at the end of this question replaces the zeros with possible numbers ranging from 1 to 9 once and non-repeating. For a given sequence of numbers, List(0, 0, 1, 5, 0, 0, 8, 0, 0), it will returns the following result. There are 720…
thlim
  • 2,908
  • 3
  • 34
  • 57
0
votes
1 answer

Array update anomaly in Python

I wrote the following code in python. Within checkd, when I update d[ii][jj], it seems as if the compiler takes its own liberties and makes all the following column entries to 1. Code: def checkd(d, level, a, b): i = len(b) j = len(a) print ['0'] +…