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: [mg60411] Re: [mg60402] basic issue with do and :=
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 16 Sep 2005 03:48:52 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

David,

That's not what I get.

Do[a[i] = i, {i, 10}]
Do[b[i] := a[i] + 1, {i, 10}]

Table[{a[i], b[i]}, {i, 10}]
{{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10},
 {10, 11}}

But this could be better done with...

Clear[a, b]
a[i_] := i
b[i_] := a[i] + 1

Table[{a[i], b[i]}, {i, 10}]
{{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10},
 {10, 11}}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/ 



From: David [mailto:isolanoster at gmail.com]
To: mathgroup at smc.vnet.net


Hi all,

this works as (I) expected

-------------------------
Do[a[i] = i, {i, 10}]
Do[b[i] =a[i]+1, {i, 10}]
-------------------------

While this doesn't:

--------------------------
Do[a[i] = i, {i, 10}]
Do[b[i] :=a[i]+1, {i, 10}]
---------------------------

[note ":=" instead of "=" on the second line].

namely the output is: "b[2]:=a[i]+1" for all i



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


Thank you in advance,

David



  • Prev by Date: Re: basic issue with do and :=
  • Next by Date: Re: basic issue with do and :=
  • Previous by thread: Re: basic issue with do and :=
  • Next by thread: Re: basic issue with do and :=