Re: A subst-antial question

Take care with the arguments with default values in this case:

> procs: comm [list proc x [info args x] [info body x]]

I am sure that a command: "info args -with_defaults x" or similar
in the core would avoid a lot of pain to the TCL developers.

Ramon Ribó

En Sun, 23 Apr 2006 17:37:55 +0200, Kip Rugger <rugger@xxxxxxxxxxxx> escribió:

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

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]] }

Compass Ing. y Sistemas Dr. Ramon Ribo ramsan@xxxxxxxxxxxxx
c/ Tuset, 8 7-2 tel. +34 93 218 19 89
08006 Barcelona, Spain fax. +34 93 396 97 46