MathGroup Archive 2009

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

Search the Archive

Re: Is it possible to dynamically construct arguments to With[]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105770] Re: Is it possible to dynamically construct arguments to With[]?
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Fri, 18 Dec 2009 06:22:38 -0500 (EST)
  • References: <hgd7ts$bn3$1@smc.vnet.net>

Leo Alekseyev schrieb:
> I've been trying to construct a list of local variables for the With
> construct dynamically, with no avail.  I tried various combinations of
> Unevaluated, Hold, and even ToBoxes/MakeExpression.  I've read that
> With[] evaluates its initialization lists in a non-standard way (cf
> http://library.wolfram.com/conferences/devconf99/villegas/UnevaluatedExpressions/Links/index_lnk_7.html)
> -- is this the problem?..  Is it possible to achieve something like
> the code below?
> 
> (* this doesn't wok *)
> Clear[aa, a];
> aa = List[Unevaluated[a = 3]];
> With[aa, a*100] // Print; (* want 300 *)

If a slightly different way to define the variable definitions is o.k.
the following would work:

Clear[aa, a];

aa = Hold[{a = 3}];

With[{vardef = Unevaluated @@ aa},
 With[vardef, a*100 + a]
 ]

With is useful for exactly these things: insert partially evaluated
expressions into held expressions. Using With to write a With is
particulary tricky :-)


hth,

albert


  • Prev by Date: Re: Is it possible to dynamically construct arguments to With[]?
  • Next by Date: Re: Repeat Data reading in one file
  • Previous by thread: Re: Is it possible to dynamically construct arguments to
  • Next by thread: Re: Is it possible to dynamically construct arguments to With[]?