To make this question easy to follow let's give some symbols a couple attributes.
Attributes[f] = {Flat};
Attributes[s] = {Orderless};
Now consider the following:
f[a, b, g[c, d], f[e, h], j, k] gives
f[a, b, g[c, d], e, h, j, k]
as expected since f is Flat
Now, we wrap Unevaluated around f
f[a, b, g[c, d], Unevaluated[f[e, h]], j, k]
This gives
f[a, b, g[c, d], Unevaluated[e], Unevaluated[h], j, k]
To understand what happened here, we use Trace
f[a, b, g[c, d], Unevaluated[f[e, h]], j, k] // Trace
{f[a, b, g[c, d], f[e, h], j, k], f[a, b, g[c, d], e, h, j, k], f[a, b, g[c, d], Unevaluated[e], Unevaluated[h], j, k]}
Finally, let's also wrap Unevaluated around s.
f[a, b, g[c, d], Unevaluated[f[e, h]], Unevaluated[s[n, m]], j, k]
f[a, b, g[c, d], Unevaluated[e], Unevaluated[h], Unevaluated[s[n, m]], j, k]
Now, here comes my question/confusion. In the case of f, the Unevaluated head was removed, so the elements of f( that has a Flat attribute ) was now spliced in and the Unevaluated head replaced on the elements of f. According to the standard evaluation process, if any part of an expression has the form Unevaluated[expr], we replace that part with expr and keep a record of the original expression (So we can later replace the Unevaluated head). Now as I've shown, if the expression expr has a head with Flat Attribute, then the expression gets spliced in (i.e. it actually gets evaluated) but as we saw with s that has the Orderless Attribute, the expression remains unevaluated as described by the Evaluation process. So why does the Flat attribute supersede Unevaluated? This shouldn't be the case according to the standard evaluation process. What am I missing?
s(withOrderlessattribute) function? How come that expression remains the same? – RunnyKine Jul 27 '13 at 19:39s, so it remains the same. – rm -rf Jul 27 '13 at 19:45