The alias trap
This might be the deepest pitfall of YCP which you will fall into if you're
trying to be too clever when changing lists and maps.
Have a look at this code:
{ map `m = $[1:11, 2:12, 3:13]; // define a map map `m1 = m; // save the current status in a helper map `m[1] = 12; // change the original map return (m == m1); // this should return false ... }
What would you expect ? Does the above code return true or false ?
Well, it returns true because it triggers the alias trap.
Assignments in YCP don't copy complex values (like lists and maps) but
rather pass references (!). So in the above example, m1 doesn't hold a
copy of m but a reference.
Changing m also changes m1.
{ map `m = $[1:11, 2:12, 3:13]; // define a map map `m1 = eval(m); // reference the result of eval() `m[1] = 12; // change the original map return (m == m1); // this does return false. }