MathGroup Archive 2010

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

Search the Archive

Re: Programatically creating delayed

  • To: mathgroup at
  • Subject: [mg110241] Re: Programatically creating delayed
  • From: Leonid Shifrin <lshifr at>
  • Date: Thu, 10 Jun 2010 08:07:09 -0400 (EDT)
  • References: <>

Hi Stuart,

for completeness, let me mention that my function will fail in case when
some of the <aelement[i]> has some value at the moment when we create our
delayed assignment. Observe:

Table[aelement[i] = i, {i, 3}]

Out[1]= {1, 2, 3}

Scan[assignElements[#, "element", 3] &, {"a", "b"}]

In[3]:= ?a



This is probably not what you would like. Here is a somewhat more
sophisticated version that is free from this flaw:

assignElementsFull[name_String, elemName_String, length_Integer] :=
  With[{heldName = ToExpression[name, InputForm, Hold]},
   Clear @@ heldName;
   With[{heldElementBaseName =
      ToExpression[name <> elemName, InputForm, Hold]},
    Block @@ Append[Map[List, heldElementBaseName],
       Evaluate[First@heldName] :=
         Table[First[heldElementBaseName][i], {i, length}]]]]]];

For example:

Clear[a, aelement];
Table[aelement[i] = i, {i, 3}];
assignElementsFull["a", "element", 3]

In[9]:= ?a



It will work even in this case:

aelement = 1;

In[11]:= assignElementsFull["a", "element", 3]

In[11]:= ?a




On Wed, Jun 9, 2010 at 4:20 AM, Stuart Nettleton <
Stuart.Nettleton at> wrote:

> Hi Leonid,
> What a wonderful little function!
> Just the thing.
> Many thanks indeed,
> Stuart
> --
> UTS CRICOS Provider Code:  00099F
> DISCLAIMER: This email message and any accompanying attachments may contain
> confidential information.  If you are not the intended recipient, do not
> read, use, disseminate, distribute or copy this message or attachments.  If
> you have received this message in error, please notify the sender
> immediately and delete this message. Any views expressed in this message
> are those of the individual sender, except where the sender expressly, and
> with authority, states them to be the views the University of Technology,
> Sydney. Before opening any attachments, please check them for viruses and
> defects.

  • Prev by Date: Re: difficulty using FindRoot
  • Next by Date: Re: Deleting Duplicates
  • Previous by thread: Re: Programatically creating delayed
  • Next by thread: Re: Programatically creating delayed