MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Previous variable affects "/."



You need to use RuleDelayed:

a = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; a /. {x_, y_} -> {x}

{{7},{7},{7},{7}}

x = 7;
a /. {x_, y_} -> {x}
a /. {x_, y_} :> {x}

{{7},{7},{7},{7}}
{{1},{3},{5},{7}}

?Rule

"lhs -> rhs represents a rule that transforms lhs to rhs."

?RuleDelayed

"lhs :> rhs represents a rule that transforms lhs to rhs, evaluating rhs
only \
when the rule is used."

Bob Hanlon



  • Prev by Date: Re: are nested patterns impossible?
  • Next by Date: ListPlot3D Color
  • Prev by thread: Re: Previous variable affects "/."
  • Next by thread: Re: Previous variable affects "/."