Problem of RuleDelayed
NameList = {"a", "b", "c", "d"};
rules = Table[NameList[[i]] <> "=" ~~ x__ ~~ "\n" :> NameList[[i]] <>
"=" ~~ OptionValue["Position"] ~~ "\n", {i, Length@NameList}];
output of rules[[1]]
is
a=~~x__~~ :>NameList[[i]]<>=~~OptionValue[Position]~~
Here, since I used RuleDelayed
, NameList
in the right-hand side is not evaluated.
One workaround is to use Rule, but Rule
may cause some warning errors concerning not a string.
rules = Table[k = i; NameList[[i]] <> "=" ~~ x__ ~~ "\n" -> NameList[[k]] <> "=" ~~
OptionValue["Position"] ~~ "\n", {i, Length@NameList}];
rules[[1]]
(*
a=~~x__~~->a=~~OptionValue[Position]~~
*)
How to solve that in the RuleDelayed
case? the effect like the Rule
case?