How to convert script into a hard coded version of it in Tcl language?

72 Views Asked by At

I am looking for a way to convert a script into its fully hard-coded version. I even don't know how this kind of function is named in software industry.. so I even don't know how to google it. Here are some examples of what I want. I don't want to use any conditional or iterative function for the outputs.

Example 1) foreach case

foreach x [list 1 2 3] { 
    puts "x=$x"
}

I'd like to convert this script to have:

puts "x=1" ; puts "x=2" ; puts "x=3"

Example 2)

set A 1
if { $A == "1" } {
    puts "A is 1"
} else {
    puts "A is not 1"
}

I want this to be :

set A 1
puts "A is 1"

Example 3) If I face comment line or unknown command or procedure, I just want to pass it to the output.

set argument 1000
UnknownProcedure $argement

This now should be :

set argument 100
UnknownProcedure 100

Thanks in advance.

1

There are 1 best solutions below

1
Chris Heithoff On

You could try trace add execution ... to commands. This is used to execute a body of code before the command itself if executed. If you can pass the arguments of your command to your trace function and also use info frame to get the proc/command name being executed, then you could use the trace function to write out a hardcoded version of the command.

See here: