Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6272
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Delayed symbol resolution |
| Date | 2011-11-08 12:21 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j9b6s2$4tr$1@smc.vnet.net> (permalink) |
| 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
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Delayed symbol resolution Rui <rui.rojo@gmail.com> - 2011-11-06 10:56 +0000 Re: Delayed symbol resolution "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-11-07 11:02 +0000 Re: Delayed symbol resolution David Bailey <dave@removedbailey.co.uk> - 2011-11-08 12:21 +0000
csiph-web