Addition commutativity violated with 'times' method

Issue #3 closed
Former user created an issue

Originally reported on Google Code with ID 3

Consider the following Lea session:
{{{
>>> (die1.times(2)) + die1
 3 :  1/216
 4 :  3/216
 5 :  6/216
 6 : 10/216
 7 : 15/216
 8 : 21/216
 9 : 25/216
10 : 27/216
11 : 27/216
12 : 25/216
13 : 21/216
14 : 15/216
15 : 10/216
16 :  6/216
17 :  3/216
18 :  1/216
>>> die1 + (die1.times(2))
 3 : 1/6
 6 : 1/6
 9 : 1/6
12 : 1/6
15 : 1/6
18 : 1/6
}}}
Both results should be the same! The second result can be explained by the binding
mechanism.
A workaround is to clone _die1_ before doing the _times(2)_:
{{{
>>> die1 + (die1.clone().times(2))
 3 :  1/216
 4 :  3/216
 5 :  6/216
 6 : 10/216
 7 : 15/216
 8 : 21/216
 9 : 25/216
10 : 27/216
11 : 27/216
12 : 25/216
}}}

Resolution: change the _times_ method to perform a clone of self.

Reported by pde@n-side.com on 2014-10-14 20:47:44

Comments (3)

  1. Former user Account Deleted
    Fixed in Lea 2
    

    Reported by pde@n-side.com on 2014-12-25 23:07:06 - Status changed: Verified

  2. Log in to comment