How can I emulate Orderless attribute?


Suppose I want an expression to automatically sort its arguments. This can be done via

SetAttributes[f, Orderless] f[3, 2, 1] (*output is f[1, 2, 3]*) 

Just as an exercise, I want to emulate this behavior myself with

f[x__] := f[Sequence @@ Sort[{x}]] 

which doesn’t work due to infinite iteration.

I would be enlightened if anyone can show me an example how to implement this.