MathGroup Archive 2000

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

Search the Archive

How to call by reference for particular argument(s)?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22093] How to call by reference for particular argument(s)?
  • From: d8442803 at student.nsysu.edu.tw (Wen-Feng Hsiao)
  • Date: Mon, 14 Feb 2000 02:03:46 -0500 (EST)
  • Organization: NSYSU
  • Sender: owner-wri-mathgroup at wolfram.com

Dear all,

I cannot figure out how to call by reference for particular arguments. 
Say, I want to design a function, which will return the position list 
where the second list locates in the first list. For example,

If one inputs the following code:

In[1]:=
res={};
myPosition[{a, b, c, d, e}, {b, d}, res];
res

It outputs {2, 4}. Since the b and d in the second list are in the 
positions 2 and 4 of first list. My code is listed below.

SetAttributes[myPosition, HoldAll];
myPosition[v1_, {e1_, e2___}, res_Symbol] := Module[{tmp},
      tmp = Flatten[Position[v1, e1]];
      If[Length[tmp] != 0,
        AppendTo[res, tmp[[1]]]];
      If[nil[{e2}] =!= nothing, (* if e2 not null *)
        myPosition[v1, {e2}, res]]];

The difficulties are when I change it to the followings, it cannot work:

In[10]:=
res={};
u1={a, b, c, d, e}; u2={b, d};
myPosition[u1, u2, res];
res

the myPosition[u1, u2, res] cannot be resolved. How can I do? Change the 
signature to myPosition[v1_Symbol, {e1_Symbol, e2___Symbol}, res_Symbol] 
does not work either. It's obvious that the intended call by reference is 
only for the third argument "ref", so please show me the rope, thanks! 
Furthermore, is there any function exists for the same purpose as 
myPosition? 

Wen-Feng


  • Prev by Date: Re: string + variable order
  • Next by Date: Re: global real variables
  • Previous by thread: Re: Simple Problem (I suppose...)
  • Next by thread: Re: How to call by reference for particular argument(s)?