Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

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 answerthis 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]

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]

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]
Rollback to Revision 3
Source Link
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]

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]

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]
deleted 746 characters in body
Source Link
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]

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]

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]
added 263 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading
edited body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading