Re: rhs of SetDelayed
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1607] Re: rhs of SetDelayed
- From: withoff (David Withoff)
- Date: Tue, 4 Jul 1995 02:48:34 -0400
- Organization: Wolfram Research, Inc.
In article <3stisq$oee at news0.cybernetics.net> c7081naa at c1.cc.univie.ac.at (Michael Probst) writes: >Hi ! >I have the following question: > >I have to define a few functions that take the same arguments. >Therefore I don't want to write the list of agguments repeatedly >and use a variable instead. >The following approach: > >lhsArg={a1_,a2_,a3_,a4_}; >rhrArg={a1,a2,a3,a4}; >f[lhsArg]:=g[rhsArg]; > >does not work. The left side is o.k. but since rhsArg is not >converted to {a1,a2,a3,a4} the right side is not. >How does one do this ? > >Thanks a lot ! >Michael >michael.probst at uibk.ac.at You'll need to force evaluation of the selected part of the right-hand side of the assignment before the assignment is evaluated. There are about a dozen ways to do this. Here is one of my favorites. In[1]:= lhsArg={a1_,a2_,a3_,a4_}; In[2]:= rhsArg={a1,a2,a3,a4}; In[3]:= ((f[lhsArg]:=g[#]) &)[rhsArg] In[4]:= ?f Global`f f[{a1_, a2_, a3_, a4_}] := g[{a1, a2, a3, a4}] Dave Withoff Research and Development Wolfram Research