Re: getting module output in replace form
- To: mathgroup at smc.vnet.net
- Subject: [mg24665] Re: getting module output in replace form
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 4 Aug 2000 01:18:53 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <8lsts5$22u@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
you multiply strings "var ->"*OuputForm[var1] and you are wondering
why this is not a replacment rule ?
You should think about the scope of your variable names
CalculateVariables[a_,b_,c_,vars_]:=
Module[{var1,var2,var3,var4},
...
Thread[vars->{var1,var2,var3,var4}]
]
and
{var1,var2}/. CalculateVariables[a,b,c,{var1,var2,var3,var4}]
will do the job as well as
CalculateVariables[a_,b_,c_]:=
Block[{v1,v2,v3,v4},
...
{var1->v1,var2->v2,var3->v3,var4->v4}
]
If you realy like the useless string construction
CalculateVariables[a_, b_, c_] :=
Module[{var1, var2, var3, var4},
var1 = a*b^c; var2 = b/c;
{"var1" -> OutputForm[var1],
"var2" -> OutputForm[var2],
"var3" -> OutputForm[var3],
"var4" -> OutputForm[var4]
} /. Rule[s_String, r_] :> Rule[ToExpression[s], r]
]
may also work.
BTW: For what is the OutputForm[] ?
Regards
Jens
Michael Gilchrist wrote:
>
> Hi,
>
> I am trying to create a module that will output a list of replacement
> rules.
>
> for example
>
> {var1, var2}/.CalculateVariables[1, 0.3, 1.222]
>
> where CalculateVariables is the module I am writing.
>
> i.e.
>
> CalculateVariables[a_, b_, c_]:=
> Module[{var1, var2, var3, var4},
>
> var1 = a* b^c;
> var2 = b/c;
> .
> .
> .
>
> {"var1 ->" OutputForm[var1],
> "var2 ->" OutputForm[var2],
> "var3 ->" OutputForm[var3],
> "var4 ->" OutputForm[var4]
> }
> ]
>
> But if I try to use the output as a replacement rule I get
>
> >ReplaceAll::"reps" {{var1-> 0.234, var2->0.323, var3-> 100001, var4->0}}
> is neither a list of replacement
> rules nor a valid dispatch table, and so cannot be used for replacing."
>
> I have tried wrapping the "vari ->" in textform, outputform, etc but get
> nowhere.
>
> I feel like I must be doing something wrong since this seems like it
> should be an easy and common use of a module. Any help would be
> appreciated.
>
> Thanks,
>
> Mike
>
> Michael Gilchrist
> Dept. of Biology
> Duke University
> Durham, NC 27708