Thanks Steve for your explanation. It was very helpful. I think I understand it now. By the way, by the .set method I meant:<br><br>class Integer:<br>    def __init__( self, number=0 ):<br>        self._int = number<br><br>
    def set( self, number ):<br>       self._int = number<br><br><br># later on....<br><br>mutableInt = Integer( 5 )<br>def change_me( var ):<br>    var.set( 6 )<br><br><br>Of course, I'd probably use overloaded operators in a more realized example.
<br>    <br><br><div><span class="gmail_quote">On 8/16/07, <b class="gmail_sendername">Steve Holden</b> <<a href="mailto:steve@holdenweb.com">steve@holdenweb.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Robert Dailey wrote:<br>> So immutable objects cannot be modified directly? I guess this means<br>> integers are immutable and the act of assigning to one is a completely<br>> new definition?<br><br>Correct. A new value is bound to the name or item on the left-hand side
<br>- remember, all variables are pointers to values, there's no way to<br>replace the value of a variable because of the automatic dereferencing.<br>And yes, immutable objects can't be modified. At all, period. Hence the
<br>name.<br><br>>                 So if I were to create a class called Integer and give<br>> it a .set() method, this would allow me to create mutable integers, and<br>> thus passing in an object of type class Integer would allow me to modify
<br>> the value from inside the function?<br>><br>Well, the .set() method wouldn't be called automatically on an<br>assignment statement but yes, if you passed an Integer object into your<br>function and called its .set() method from inside then it should work.
<br><br>As long as you get your mutable integer implementation correct, of<br>course ;-). I'd suggest delegating everything except the .set() method<br>to the underlying integer value.<br><br>regards<br>  Steve<br>--<br>
Steve Holden        +1 571 484 6266   +1 800 494 3119<br>Holden Web LLC/Ltd           <a href="http://www.holdenweb.com">http://www.holdenweb.com</a><br>Skype: holdenweb      <a href="http://del.icio.us/steve.holden">http://del.icio.us/steve.holden
</a><br>--------------- Asciimercial ------------------<br>Get on the web: Blog, lens and tag the Internet<br>Many services currently offer free registration<br>----------- Thank You for Reading -------------<br></blockquote>
</div><br>