Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Telling Mathematica that a symbol is going to be a List?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50823] Re: [mg50817] Telling Mathematica that a symbol is going to be a List?
  • From: Andrzej Kozlowski <andrzej at akikoz.net>
  • Date: Wed, 22 Sep 2004 04:52:01 -0400 (EDT)
  • References: <200409220411.AAA18738@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 22 Sep 2004, at 13:11, AES/newspost wrote:

> *This message was transferred with a trial version of CommuniGate(tm) 
> Pro*
> I want to define a function containing parameters that are going to be
> elements in a list, e.g. something like
>
>   m := { { d[[1]], 0, 0}, {0, d[[2]], 0}, {0, 0, d[[3]]}
>
> but not define the list of values of  d  until later (and not put the
> parameters in as explicit arguments of  m  just to keep the appearance
> less cluttered and typing easier).
>
> If I then give an input line
>
>     m /. {d -> {d1, d2, d3} } // MatrixForm
>
> I get "Part::partd" errors -- but the matrix then displays correctly.
>
> I can of course just Off[] the errors -- but is there a better way.
>
It depends on what you mean by "better". I don't think there is a way 
which does not require more typing, but you can avoid pre-mature 
evaluation attempt in several ways, e.g. by having HoldForm or Hold in 
your definition of m, and using Release hold after replacement:


m :=HoldForm[ { { d[[1]], 0, 0}, {0, d[[2]], 0}, {0, 0, d[[3]]}}]

ReleaseHold[m/. {d -> {d1, d2, d3} } ]// MatrixForm

or by replacing the outer list by some undefined function wiht the 
HoldAll attribute:


SetAttributes[L,HoldAll]

m :=L[ { d[[1]], 0, 0}, {0, d[[2]], 0}, {0, 0, d[[3]]}]

m/. {d -> {d1, d2, d3} }/.L->List


and so on. But I suspect that there may be a better way to achieve what 
you are ultimately hoping to do without going into all this trouble.


Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/~andrzej/
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: How to simplify to a result that is real
  • Next by Date: PhasePlot
  • Previous by thread: Re: Telling Mathematica that a symbol is going to be a List?
  • Next by thread: Re: Telling Mathematica that a symbol is going to be a List?