MathGroup Archive 1995

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

Search the Archive

Re: rhs of SetDelayed

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1599] Re: rhs of SetDelayed
  • From: rubin at msu.edu (Paul A. Rubin)
  • Date: Tue, 4 Jul 1995 01:28:26 -0400
  • Organization: Michigan State University

In article <3stisq$oee at news0.cybernetics.net>,
   c7081naa at c1.cc.univie.ac.at (Michael Probst) wrote:
->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 want $PreRead, which preprocesses input lines:

In[]:=  $PreRead = 
          StringReplace[ #,
                         {"lhsArg" -> "a1_,a2_,a3_,a4_",
                          "rhsArg" -> "a1,a2,a3,a4"} ]&;
In[]:=  f[lhsArg]:=g[rhsArg];
In[]:=  ?f
Out[]=  Global`f
        f[a1_, a2_, a3_, a4_] := g[a1, a2, a3, a4]
In[]:=  f[1,2,3,4]
Out[]=  g[1, 2, 3, 4]
In[]:=  $PreRead =.  (* clears $PreRead *)

I was not sure if you literally wanted a single list as the argument or if 
you really meant to use a *sequence* of arguments.  The latter is 
demonstrated above; for the former, just add braces ({}) inside the quotes 
in StringReplace.

Paul

**************************************************************************
* Paul A. Rubin                                  Phone: (517) 432-3509   *
* Department of Management                       Fax:   (517) 432-1111   *
* Eli Broad Graduate School of Management        Net:   RUBIN at MSU.EDU    *
* Michigan State University                                              *
* East Lansing, MI  48824-1122  (USA)                                    *
**************************************************************************
Mathematicians are like Frenchmen:  whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different.                                    J. W. v. GOETHE


  • Prev by Date: Re:Fitting data on a vertical line
  • Next by Date: Q: Random[]
  • Previous by thread: Re: rhs of SetDelayed
  • Next by thread: Re: rhs of SetDelayed