Skip to main content
add missing indentation
Source Link
Alan
  • 13.8k
  • 21
  • 41

Use With instead of Module?

ClearAll[a, b, c, d, pick, ex, co]

ClearAll[a, b, c, d, pick, ex, co]

ExpandPick[exp_] := With[{
   p = FirstPosition[exp, _pick]
   }, With[{
    x = First@Extract[exp, p],
    y = Last@Extract[exp, p]
    },
   ReplacePart[exp, p :> ex[Function[co, {co[x], co[y]}]]]]]

Use With instead of Module?

ClearAll[a, b, c, d, pick, ex, co]

ExpandPick[exp_] := With[{
   p = FirstPosition[exp, _pick]
   }, With[{
    x = First@Extract[exp, p],
    y = Last@Extract[exp, p]
    },
   ReplacePart[exp, p :> ex[Function[co, {co[x], co[y]}]]]]]

Use With instead of Module?

ClearAll[a, b, c, d, pick, ex, co]

ExpandPick[exp_] := With[{
   p = FirstPosition[exp, _pick]
   }, With[{
    x = First@Extract[exp, p],
    y = Last@Extract[exp, p]
    },
   ReplacePart[exp, p :> ex[Function[co, {co[x], co[y]}]]]]]
Source Link
Alan
  • 13.8k
  • 21
  • 41

Use With instead of Module?

ClearAll[a, b, c, d, pick, ex, co]

ExpandPick[exp_] := With[{
   p = FirstPosition[exp, _pick]
   }, With[{
    x = First@Extract[exp, p],
    y = Last@Extract[exp, p]
    },
   ReplacePart[exp, p :> ex[Function[co, {co[x], co[y]}]]]]]