On Tue, Feb 15, 2011 at 2:25 PM, Noorul Islam K M <noo...@noorul.com> wrote:
> openbala <damodaran.bal...@gmail.com> writes:
>
>> On Mon, Feb 14, 2011 at 12:52 PM, Kenneth Gonsalves
>> <law...@thenilgiris.com> wrote:
>>
>
> What is wrong below?
>

There is nothing wrong. Certain programming languages try to handle
certain things differently.
There is a new wave of languages that take immutability and
referential transparency very seriously. (please use your favourite
search engine to figure out what they are)

The gist of immutability is that any operations on a data structure
should not change its data structure. (for e.g. java's String class is
immutable)
In python the "reverse()" method is mutating the list instead of
returning a new output.

This is the output in ruby:

$ numbers = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
$ numbers.reverse
=> [5, 4, 3, 2, 1]
$ numbers
=> [1, 2, 3, 4, 5]
$

Note that the numbers list has not changed even after calling 'reverse' method.

The general consensus is that mutability is bad for programming. YMMV.

>>>> numbers = [1, 2, 3, 4, 5]
>>>> numbers.reverse()
>>>> numbers
> [5, 4, 3, 2, 1]
>>>> list.reverse(numbers)
>>>> numbers
> [1, 2, 3, 4, 5]
>
> Thanks and Regards
> Noorul
_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc

Reply via email to