Skip to main content
5 of 6
Rollback to Revision 3
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

When you do this, localization kicks in and renames one of the x to avoid conflict:

enter image description here

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 answer.

enter image description here

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]
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k