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