MathGroup Archive 1996

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

Search the Archive

Re: Re: iterator strings as lists?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3557] Re: [mg3528] Re: iterator strings as lists?
  • From: Richard Mercer <richard at seuss.math.wright.edu>
  • Date: Mon, 25 Mar 1996 21:32:14 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Dave Wagner wrote, in reference to the HoldAll attribute of Table,

>  I don't know what the design rationale for this is.  It
>  seems to me like Table could get by with the HoldFirst
>  attribute, but maybe there's some pathological case of
>  which we're not aware that precludes this.
>  


There is undoubtedly more than one reason, but one at least is not so  
pathological. Table allows you to use as an index a variable that  
already has an assigned value.

j = 8;
Table[i*j,{i,1,3},{j,1,2}]

{{1, 2}, {2, 4}, {3, 6}}

If the HoldAll attribute is removed, this feature is lost.

Unprotect[Table];
Attributes[Table] = {HoldFirst};

Table[i*j,{i,1,3},{j,1,2}]
Table::itraw: Raw object 8 cannot be used as an iterator.
Table[i j, {i, 1, 3}, {8, 1, 2}]

This situation also occurs with Plot. Plot has the HoldAll attribute so  
that the following command produces the expected graph with no  
problems.

x = 8;
Plot[x^2,{x,0,1}];

These features are essential for non-expert users, who assign values to  
commonly used variables with reckless abandon (experts know better).
If you don't see yourself having this particular problem, my guess is  
that changing the HoldAll attribute to HoldFirst would not cause any  
serious problems.

Richard Mercer


==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: ListContourPlot: AxesLabels? (Q)
  • Next by Date: mathematica-macppp conflict
  • Previous by thread: Re: iterator strings as lists?
  • Next by thread: Re: iterator strings as lists?