1,220 questions
1 vote
2 answers
108 views
Modify a mutable vector in chunks
I am very new at the ST monad, and have reached my wits end in trying to correct the error in the code below. I have a buildChain function, which we can assume works, takes an Int and returns a list ...
0 votes
1 answer
84 views
Value of a mutable variable is not updated in XUnit test
I wrote an XUnit test in F# for a function that updates a mutable variable: [<Fact>] let ``UpdatePlayerOneAmountTests`` () = //-- Arrange let input = new StringReader "10" ...
2 votes
1 answer
67 views
Strange behavior when partitioning list of tuples into different lists [duplicate]
I found some really unexpected behavior today using python 3.12.4. I am trying to sort a list of tuples into 2 different lists in a list of lists based on the first number of the tuple. Instead, each ...
2 votes
2 answers
112 views
Lambda static vs mutable variable
I have encountered a lambda with static variable in the following answer https://stackoverflow.com/a/79631994/2894535 : EXPECT_CALL(my_mock, foo(_)) .WillRepeatedly(InvokeWithoutArgs([](){ ...
0 votes
0 answers
32 views
Nested mutable and immutable borrows in rust [duplicate]
MRE: enum MRE_Enum { variant1, variant2, } struct MRE_Struct { dummy1: Vec<MRE_Enum>, dummy2: isize, } // Private functions together impl MRE_Struct { fn foo(&mut self) ...
2 votes
4 answers
157 views
Getting a mutable element from a std::set, for operations that won't break the order
I've got a data type that consists of actual data and an id: struct Data { int value; int DataId; }; I've got a collection of these data from which I have to frequently get an element based ...
2 votes
0 answers
62 views
Why does Rust scope include the else of an if conditional as well? [duplicate]
I have the below min repro application which is meant to build a graph (tree) from a vec (split string). (It is meant to be part of a larger loop that would modify the graph/tree multiple times.) The ...
0 votes
0 answers
24 views
Making nested lists Vs making nested sets (without frozensets)
If I wanted to make a nested set: nested_set = {{1, 2, 3}, {6, 4, 5}, {12, 8, 5, 7}} It would give the error: TypeError: unhashable type: 'set' However if I wanted to make a nested list: nested_list =...
2 votes
0 answers
100 views
Assign to an expression
I'm learning Rust so getting to grips with mutable and non-mutable. I've copied code from several projects and it works well. This is the ode_solver function for a two-pool compartmental model. My ...
0 votes
0 answers
37 views
In Unity with C# 8, how to use reflection to set a mutable field value? [duplicate]
Here is a simple example: [System.Serializable] public struct PlayerData { public string name; public int level; public float health; } [Test] ...
0 votes
1 answer
88 views
Start a forever thread with a expired objects loop, removing those objects, in rust
I am writing a service, and I want to run a loop forever that checks for some expired objects and removes them if too old. pub struct Obj { expired: NaiveDateTime, } pub struct Maintainer { ...
0 votes
1 answer
134 views
How to update a collection inside a struct in rust?
Probably this question already has been asked, maybe with different wording, but I couldn't find it. If this gets closed due to this, apologies, but I did try before. In fact, the problem is simple: ...
1 vote
1 answer
104 views
Does a mutable reference means an ownership loss in Rust?
This exercice from Rustlings, once corrected, gives: fn move_semantics4() { let mut x = Vec::new(); let y = &mut x; y.push(42); let z = &mut x; z....
-1 votes
1 answer
71 views
Python List NOT modifying in place while splicing?
I have a list of chars. I want to insert a string in between the chars at given index. For that I wrote a function to insert the item (string) in the list in-place. The list inside the function is ...
2 votes
2 answers
142 views
Is Python function immutable?
I have import copy class A: _member_a: dict[str, str] _member_b: Callable def set_b(self, func): self._member_b = func def deep_copy(self): return copy.deepcopy(self) I ...