MathGroup Archive 2011

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

Search the Archive

Re: Delayed symbol resolution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122739] Re: Delayed symbol resolution
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Tue, 8 Nov 2011 07:16:38 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j95p5g$m5l$1@smc.vnet.net>

On 06/11/2011 10:56, Rui wrote:
> A few scattered times in my not too long Mathematica history I've found myself facing a similar simple problem that always required particular attention to solve it.
> The problem, in broad terms: needing to insert a symbol whose context is the current context at the time the code is being evaluated. Of course, this might mean the symbol could be used as an argument to a HoldAll function that receives a Symbol, so it can't be evaluated. So I end up using MakeExpression or ToExpression wrapping the result in Hold and then doing some (to me) hard expression manipulation with Applies, RemoveHolds and Replaces which results in a code that might work but is far from neat and understandable. I might add, the heavy expression manipulation and Holds and replacements and etc were never my strong suit...
>
> So finally I'm doing what I should have done from the start:
> * Ask here if there's a simple way to solve it
> * Create a short function in a package.
>
> I'll do the second one right now, and if you make me realise it's redundant I'll throw it away. If not, I'll share it.
>
> I'm thinking of something Block-like such as
> WithDelayedSymbols[{x, y}, (* code using x and  y*)]
> where every appearance of x and y would be replaced by the current context symbols of ToExpression[x] and ToExpression[y] prior to any evaluation.
> Also, a
> BlockDelayedSymbols[{x, y}, ...] which also adds dynamic scoping like Block
>
> Rui Rojo
>
I am not really sure what you want to do - an actual example would help 
- but you can insert a symbol inside HoldAll (provided it doesn't have a 
value) using:

xx=someSymbol;

HoldAll[Evaluate[xx]]

or

With[{xx=xx},HoldAll[xx]]

David Bailey
http://www.dbaileyconsultancy.co.uk




  • Prev by Date: Re: Scoping of pattern names
  • Next by Date: Re: Import files on accessible URL and save in
  • Previous by thread: Re: Delayed symbol resolution
  • Next by thread: NDSolve with 3 independent variables