MathGroup Archive 2006

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

Search the Archive

Re: Array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69252] Re: Array
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 3 Sep 2006 23:46:52 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <eddptn$3q3$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bruce Colletti wrote:
> The command:
> 
>    {A[1], A[2], A[3]} = {1, 2, 3}
> 
> assigns a value to each A-variable.  However, the command:
> 
>    Array[A,3] = {1,2,3}
> 
> generates an error message.
> 
> What is the difference between the two lines?
> 
> Thankx.
> 
> Bruce
> 

Hi Bruce,

The function Set, or = sign, has the attribute HoldFirst [1], that is 
the function does not create the array first but try to assign the list 
to the symbol Array[A, 3] and Array is of course write protected since 
it is a built-in function. Use Evaluate to force the evaluation of the 
first argument [2].

In[1]:=
Array[A, 3] = {1, 2, 3};

--> Set::"write" : "Tag (Array) in (Array[A, 3]) is Protected. More...

In[2]:=
Attributes[Set]

Out[2]=
{HoldFirst, Protected, SequenceHold}

In[3]:=
Evaluate[Array[A, 3]] = {1, 2, 3};

In[4]:=
A[1]

Out[4]=
1

Regards,
Jean-Marc

[1] http://documents.wolfram.com/mathematica/functions/HoldFirst

[2] http://documents.wolfram.com/mathematica/functions/Evaluate


  • Prev by Date: comboboxes and paste to notebook
  • Next by Date: Books on learning mathematics with Mathematica
  • Previous by thread: Re: Array
  • Next by thread: how to identify plane and measuring planar area