MathGroup Archive 2011

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

Search the Archive

Delayed symbol resolution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122686] Delayed symbol resolution
  • From: Rui <rui.rojo at gmail.com>
  • Date: Sun, 6 Nov 2011 05:54:50 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Reply-to: comp.soft-sys.math.mathematica at googlegroups.com

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



  • Prev by Date: Re: How to evaluate parts of an expression, but not other parts?
  • Next by Date: Re: Solving simple equations
  • Previous by thread: Format and MakeBoxes in depth - Part 1
  • Next by thread: Re: Delayed symbol resolution