MathGroup Archive 1995

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

Search the Archive

Re: rhs of SetDelayed

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1657] Re: [mg1584] rhs of SetDelayed
  • From: Allan Hayes <hay%haystack at christensen.cybernetics.net>
  • Date: Tue, 11 Jul 1995 01:57:11 -0400

In [mg1584] rhs of SetDelayed
Michael Probst <c7081naa at c1.cc.univie.ac.at>
Wrote

>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 ?


Michael,

The following, using With, may help: I give two variants.

Clear[f,lhsArg,rhsArg,a1,a2,a3,a4]

{a1, a2, a3, a4} = {1, 2, 3, 4};
	(*to check there is no unwanted evaluation *)

With[{lhsArg ={a1_,a2_,a3_,a4_},rhsArg:={a1,a2,a3,a4}},
	f[lhsArg]:= g[rhsArg]];

With[{lhsArg = Sequence[a1_,a2_,a3_,a4_], 	
      rhsArg:= Sequence[a1,a2,a3,a4]
    },
	f[lhsArg]:= g[rhsArg]
];

?f
	Global`f
	f[{a1_, a2_, a3_, a4_}] := g[{a1, a2, a3, a4}]
	f[a1_, a2_, a3_, a4_] := g[a1, a2, a3, a4]


Notice the use of := in With to simply insert unevaluated.

Compare
Clear[f];

With[{lhsArg ={a1_,a2_,a3_,a4_},rhsArg ={a1,a2,a3,a4}},
	f[lhsArg]:= g[rhsArg];]

?f
	Global`f
	f[{a1_, a2_, a3_, a4_}] := g[{1, 2, 3, 4}]
	
g will never be evaluated.

Allan Hayes
hay at haystack.demon.co.uk


  • Prev by Date: Re: Crossreference, code documentation
  • Next by Date: Re: Masked array operations
  • Previous by thread: Re: rhs of SetDelayed
  • Next by thread: Re: rhs of SetDelayed