MathGroup Archive 2005

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

Search the Archive

Re: basic issue with do and :=

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60444] Re: basic issue with do and :=
  • From: "dkr" <dkrjeg at adelphia.net>
  • Date: Fri, 16 Sep 2005 03:50:39 -0400 (EDT)
  • References: <dgbevg$fol$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

>> Is there any compact way to define: "b[i] :=a[i]+1" for all i ?

Use a pattern variable on the lefthand side:

In[8]:=
a[i_]:=i;
b[i_]:=a[i]+1;
In[10]:=
Table[{a[i],b[i]},{i,10}]
Out[10]=
{{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10},{10,11}}

In your expression Do[b[i] :=a[i]+1, {i, 10}] , what is happening is
that i gets set to a certain value, that value is then fed to b[i] (but
not a[i]+1, since SetDelayed does not immediately evaluate its
righthand side.


  • Prev by Date: number of digits in n^p
  • Next by Date: Re: Replacement rule for a quotient
  • Previous by thread: Re: basic issue with do and :=
  • Next by thread: Re: basic issue with do and :=