immutable

Searching for hints on how to implement immutable data structures in C++

Hi everybody, I'm wondering how to implement immutable data structures in C++ (or C). I'm searching for a book or paper (or a relatively simple and documented implementation) on the subject and I haven't managed to find one for now so I decided to ask for hints. Thanks in advance for your answers. ...

Remove specific characters from a string in python

I'm trying to remove specific characters from a string using python. This is the code i'm using right now. Unfortunately it appears to do nothing to the string?? for char in line: if char in " ?.!/;:": line.replace(char,'') ...

os.path.exists not accepting variable input

Whenever I call os.path.exists(variable) it will return false but if I call os.path.exists('/this/is/my/path') it will return true. import os import sys test = None print("Test directory") test= sys.stdin.readline() test.strip('\n') print(os.path.exists(test)) I know that os.path.exists can return false if there is a permissions erro...

If Java Strings are immutable and StringBuilder is mutable why they wasting same ammount of memory in my code?

I ran those code and I got some questions, this kinda got wierd. Using String: while(true) { String s = String.valueOf(System.currentTimeMillis()); System.out.println(s); Thread.sleep(10); } Using StringBuilder: StringBuilder s = null; while(true) { s = new StringBuilder(); s.append(System.current...

Why are C# number types immutable?

Why are ints and doubles immutable? What is the purpose of returning a new object each time you want to change the value? The reason I ask is because I'm making a class: BoundedInt, which has a value and an upper and lower bound. So I was wondering: should I make this type immutable too? (Or should it be a struct?) ...

Generating immutable cyclic data structrures

Suppose I have this simple class: public class Pair { public readonly object first; public readonly object second; public Pair(object first, object second) { this.first = first; this.second = second; } } It would be impossible to generate a cyclic graph of pairs. How would you create a similar class, ...

Scala assigning vals

Why isn't it possible to have this: def main(args:Array[String]) { val whatever:String // have it uninitialized here if(someCondition) { whatever = "final value" // initialize it here } } I don't understand why this shouldn't be legal.I know that I can make it a var,but why do we have to initialize the val exactly when we ...

In stackless python, is data sent over a channel immutable?

I have a typical producer, consumer pattern. If the producer sends an object over a channel, the producer is blocked until the consumer accepts the object. After the consumer accepts the object, the producer alters the object in some way. Does the consumer see the object get altered? Or was there an implicit copy when sending the data ov...