Re: A subst-antial question
- From: rugger@xxxxxxxxxxxx (Kip Rugger)
- Date: 23 Apr 2006 10:37:55 -0500
Busirane <john.j.seal@xxxxxxxxx> wrote:
Don Porter wrote:
% ::comm::comm send 51395 [list array set foo $pairs]
Let me restate the question. Suppose I have a script:
set script {
array set foo $pairs
set bar $somethingElse
}
This would typically have been passed into a procedure instead of set
literally, where "pairs" and "somethingElse" would be defined in the
caller's context. I want to be able to run the same script either
locally or remotely. No preprocessing is necessary to run it locally.
I know I have to substitute variables locally before I can set them
remotely, and a simple [subst] won't do it. I don't think
[list]-ifying it in the caller's context, as you suggest, will work
either, because it'd lose the whitespace command delimiters. I could
process each line, substituting each word on the line and preserving it
as a single word, then reassembling the substituted script, but is that
the only way?
I may have oversimplified things in my original posting by using a
single-line script... sorry!
Let's restate what you are asking to do, but with some precision.
0) You have an arbitrary script.
1) You wish to perform macro substitution on some of the variable
references in that script.
2) You wish to write that script to external media, and then
read it back and execute it in another interpreter. Part of
this operation involves storing the context of the script (global
variables, open files, random-number states, loaded extensions, etc).
Are you really asking for the solutions to these rather general
problems? Or, more likely, are you having trouble stating your real
question?
I suspect you are trying to do a simplified version of 2). You have
a set of variables whose values you wish to replicate, so that a
not-so-arbitrary script can be executed in another interpreter.
scalars: comm [list set x $x]
arrays: comm [list array set x [array get x]]
procs: comm [list proc x [info args x] [info body x]]
scripts: comm { ... $x ... }
or set s { ... $x ... }; comm $s
And the loop version of these is just a simple foreach:
foreach var { a b c } { comm [list set $var [set $var]] }
foreach arr { a b c } { comm [list array set $arr [array get $arr]] }
.
- Follow-Ups:
- Re: A subst-antial question
- From: Busirane
- Re: A subst-antial question
- From: Ramon Ribó
- Re: A subst-antial question
- References:
- A subst-antial question
- From: Busirane
- Re: A subst-antial question
- From: Don Porter
- Re: A subst-antial question
- From: Busirane
- A subst-antial question
- Prev by Date: Re: Regexp help
- Next by Date: Re: A subst-antial question
- Previous by thread: Re: A subst-antial question
- Next by thread: Re: A subst-antial question
- Index(es):
Relevant Pages
|