[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] a Bug ?




Not a bug. You are combining the nondestructive operation 'collect' with the destructive operation 'insert' and that is causing a mess.
a better way to do this is:

x = [[1,2],[3,4],[5,6],[6,7],[8,9.10]];

y = x.collect {|e,i| ["a"++i] ++ e };

x is not modified and y contains the result.


On Sep 7, 2005, at 2:08 AM, Amos Elmaliah wrote:

Hi List!

WHY :

x = [ [ "obj", "cube" ], [ "obj", "colorRGB", 0, 1, 0 ], [ "obj", "alpha" ], [ "obj", "gemhead", 50 ], [ "obj", "route", "priority", "alpha", "size"
], [ "msg", "set", $1 ] ];

    x.collect({|cmd, i| cmd.insert(0, "a-"++i) } );

x = [ [ obj, cube ], [ a-1, obj, colorRGB, 0, 1, 0 ], [ obj, alpha ],
[ a-3, obj, gemhead, 50 ], [ a-4, obj, route, priority, alpha, size ],
[ a-5, msg, set, 1 ] ]


BUT:

x = [[1,2],[3,4],[5,6],[6,7],[8,9.10]]


    x.collect({|e,i| e.insert(0, "a"++i) })

    x = [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 6, 7 ], [ 8, 9.1 ] ]


thanks !!

Amos Elmaliah.


_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users