MathGroup Archive 2008

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

Search the Archive

Re: Mixing immediate assignment and delayed assignment

Kristian Schmidt wrote:
> Hello
> I have some code akin to this:
> In[261]:= list1 = Table[Null, {j, 1, 5}];
> For[i = 1, i <= 5, i++,
>  list1[[i]] := some_list[[i]];
>  ]
> Which after its execution will have list1 filled with these references:
> {some_list[[6]], some_list[[6]], some_list[[6]], some_list[[6]], 
>  some_list[[6]]}
> But I would like the list to be filled with:
> {some_list[[1]], some_list[[2]], some_list[[3]], some_list[[4]], 
>  some_list[[5]]}
> In other words, I would like the assignment of "i" to be immediate, but the assignment of some_list to be delayed, as the list will be updated periodically.

Inject the value using With[].  Also note that some_list is not a valid 
symbol name in Mathematica: underscores are used in patterns.

In[1]:= list1 = Table[Null, {j, 5}];

     With[{i = j}, list1[[i]] := sl[[i]] ],
     {j, Length[list1]}

In[3]:= OwnValues[list1]
{HoldPattern[list1] :> {sl[[1]], sl[[2]], sl[[3]], sl[[4]], sl[[5]]}}

  • Prev by Date: Re: Re: smallest fraction
  • Next by Date: Re: Nice Mathematica stylestyle for Book Appendix
  • Previous by thread: Mixing immediate assignment and delayed assignment
  • Next by thread: Re: Mixing immediate assignment and delayed assignment