# Why patterns names aren't scoped by default?

In a recent question [1] OP asked how to make Module scope working inside Set, so how to get:

f[x$123_] = x$123


f[x_] = x


from

Module[{x}, Defer[f[x_] = x] ]


It is stated in Details of Module ref page that:

Before evaluating expr, Module substitutes new symbols for each of the local variables that appear anywhere in expr except as local variables in scoping constructs.

My question is - why this exception is present? What common usage cases dictated this behaviour? Does this makes something safer?

I don't complain, I'm just curious. I don't know why Module can't just change every x it sees to x$1232? Current rule looks like an exception which causes only troubles. It is even more interesting when we introduce y which will rename x Module[{x , y = 1}, Defer[f[x_] = x y] ]  f[x$_] = x$y$7519

• Sorry, I didn't follow everything. Is this about weirdness like this? x = 1; Module[{x = 2}, Print[x_ -> x]] Note how the x within the Module is actually evaluating to its global value. Jul 3 '16 at 10:21
• SetSystemOptions["StrictLexicalScoping" -> True] fixes that. Jul 3 '16 at 10:56
• Is this a duplicate? Be sure to read all the comments. I asked there why StrictLexicalScoping is not turned on by default. Jul 3 '16 at 11:04
• @Szabolcs I'm aware of that option but it gives f[x$_] = x$ not x$1231. Moreover, the question is why a particular implementation was chosen. – Kuba Jul 3 '16 at 11:04 • @Mr.Wizard While Leonid says he will explain "what and why" he rather explains "what and how". There is a statement "such renaming h -> h$123 has to be prevented." which my question really ask about. Why it has to be prevented. You have started to explain it too but with not real examples "why" it is not desired for Set and Rule. So if you want to extend your thought about that specific part, here is a good place ;)
– Kuba
Jul 8 '16 at 7:12