Frage

How can I rename an existing tcl command in a slave interpreter?

In other words

interp create test
test alias __proc proc

test eval {
  __proc hello {} {
    puts "hiya"
  }
  hello
}

This unfortunately does not work. However, if I hide and expose under a different name that works. But, I would like to use both commands proc and __proc - so I would prefer to use aliases, or any other way...

War es hilfreich?

Lösung

The alias command on a Tcl interpreter allows you to create a command in an interpreter that causes code to run in a different interpreter. So that's not what you want.

I think the following does what you want:

interp create test

test eval {
  rename proc __proc

  __proc hello {} {
        puts "hiya"
  }

  hello
}

You can then combine the creation of the interpreter with the renaming of the proc command as follows:

proc myinterp {interpName newProcName} {
   interp create $interpName
   $interpName eval "rename proc $newProcName"
}

myinterp test func

test eval { func greet {} { puts "hello" } }
test eval ( greet }

Andere Tipps

You can do either

interp alias test __proc test proc

in the main interp or

interp alias {} __proc {} proc

in the slave, so both of the following scrips work:

interp create test
interp alias test __proc test proc

test eval {
  __proc hello {} {
    puts "hiya"
  }
  hello
}

or

interp create test

test eval {
interp alias {} __proc {} proc
  __proc hello {} {
    puts "hiya"
  }
  hello
}

test alias __proc proc is the same as interp alias test __proc {} proc, that means that __proc in the slave will call proc in the master.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top