When you do this, localization kicks in and renames one of the x
to avoid conflict:
This is in general beneficial, and designed to prevent trouble. In some situations, however, you don't want this localization-through-renaming to happen. In that case you can use Replace
instead of With
to replace y
by x
.
I like to keep using the syntax of With
though, so in these situations I tend to use the withRules
function defined in the middle of this answerthis answer.
The caveat with withRules
is precisely that it does not truly localize, so you need to be very careful when using it.
Update:
Version 10-specific template based solution:
template = (draw[x_] := Cylinder[{{#y, 0, 0}, {#y + 1, 0, 1}}, 0.1]) &
template[<| "y" :> x |>]
?draw
draw[x_]:=Cylinder[{{x,0,0},{x+1,0,1}},0.1]