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




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



Relevant Pages

  • Re: failed substitution
    ... I wrote a short script ... extension) and substitute it for '_a'. ... the foreach code can at least be shortened to: ... on the full path and not the basename. ...
    (perl.beginners)
  • Re: Error on "cryptorati.com" - adacrypt
    ... Her substitute was modern, cognitive, and yells along with the ... script. ...
    (sci.crypt)
  • Re: failed substitution
    ... I have a number of jpegs I wanted to rename. ... I wrote a short script ... extension) and substitute it for '_a'. ... This makes the malfunction dependent from the contents in $dir. ...
    (perl.beginners)
  • Question on perl script.
    ... I am very new to the perl language and don't know much about it. ... two values are being passed to this script. ... The perl command processes the inrptfile by substituting the first line ... How can I make it substitute something completely different ...
    (comp.unix.shell)
  • Re: A subst-antial question
    ... Suppose I have a script: ... I know I have to substitute variables locally before I can set them ... stuff with $foo in it ... An alternative, in Tcl 8.5 (or 8.4 with the dict package), would be to not perform the substitutions locally, but instead to snapshot the environment of the script as a dict, and then send that along with the code to be evaluated remotely using: ...
    (comp.lang.tcl)