Executing:
replace[res_] := res /. {a_Integer, b_Integer} :> (a + b);
l1 = <|"respID" -> {1,2} , "key2" -> <|"key2" -> {2, 1}|>|>;
l2 = {"respID" -> {1,2} , "key2" -> {"key2" -> {2, 1}}};
replace[l1]
replace[l2]
In version 10.2 I get:
<|"respID" -> 3, "key2" -> <|"key2" -> 3|>|> {"respID" -> 3, "key2" -> {"key2" -> 3}}
And in version 10.3:
<|"respID" -> 1 + 2, "key2" -> <|"key2" -> 2 + 1|>|> {"respID" -> 3, "key2" -> {"key2" -> 3}}
Is this a bug? How can I force the evaluation as in 10.2, to prevent Hold[2+1] and get 3?
As a temporary solution I'm using a very clumsy function similar to this:
Needs["GeneralUtilities`"]
replace2[res_] := Module[{temp = res/.Association-> List},
temp = temp /. {a_Integer, b_Integer} :> (a + b);
ToAssociations@temp
]
replace2@l1
<|"respID" -> 3, "key2" -> <|"key2" -> 3|>|>
RuleCondition[a + b]as the RHS of the rule, or afterwards using egMap[Identity, replace[l1], -1]– Simon Woods Jan 18 '16 at 21:34RuleConditionis undocumented? Insteresting,replace[res_] := res /. {a_Integer, b_Integer} :> RuleCondition[a + b];works. – Murta Jan 18 '16 at 21:38RuleCondition– Simon Woods Jan 18 '16 at 21:40Associationserves asHoldAllCompletecontainer (after the key-value pairs have been added, they are not re-evaluated), the new behavior seems more logical to me than the old one. – Leonid Shifrin Jan 18 '16 at 22:18Replacereported there is fine, and as it should be. I will talk to Tali about this when I get a chance. – Leonid Shifrin Jun 05 '16 at 10:08