Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What is the syntax of calling a procedure in TCL?

Status
Not open for further replies.
Hai sunray.,

We can send using command line arguments in tcl................
What is the syntax for that? Is the following syntax for that?

setenv variable1 "$1";

setenv variable2 "$1"

I have another question as below

Question: Suppose we have many files where each file contains a portion of the main script. Now suppose we set some variables in one of such files. How can made that settings available in all other files while executing the script? Is there any way so that one file can be linked to the other file?
 
Last edited:

Environmental variables can be used by defining in one file itself.. but u should define before u call... So define all environmental variable in the initial file..........
 

Environmental variables can be used by defining in one file itself.. but u should define before u call... So define all environmental variable in the initial file..........

What are the differences between environment variable and variables that are defined by using the set command (set variable variablename)? The difference is not still clear.

You also did not answer to my another query

What is the syntax for using command line argument in tcl? Is the following syntax correct for command line argument in tcl?

setenv variable1 "$1";

setenv variable2 "$1"
 

by declaring as environmental variable u can call where ever u want (u can also call in other programs even in other languages like tcl cshell perl skill etc.. based on that syntax )

Declaring as variable is local so u cant call outside that specific program

command line arguments:-
syntax for command line arguments in tcl

Syntax:-
tclsh filename.tcl $variable_name
 

command line arguments:-
syntax for command line arguments in tcl
Syntax:-
tclsh filename.tcl $variable_name

I think the command to run the tcl script is

tclsh filename.tcl arg1 arg2 arg3.

Inside the filename.tcl this arguments arg1, arg2 and arg3 are needed to be set/collected as a variable. I wanted to know the syntax to collect this arg1, arg2 and arg3 in tcl. Please let me know that. Is it that the following is the syntax for that?

setenv variable1 "$1";

setenv variable2 "$1" ;

Declaring as variable is local so u cant call outside that specific program

Do you want to mean that declaring the variable by using the 'set' command makes the variable local variable? Is it that this local variable can be called from any script out of all scripts that makes the complete program?

- - - Updated - - -

I HAVE ANOTHER QUESTION

Question: What is the purpose of writing "#!/usr/bin/env tclsh" at the beginning of a tcl script.
 
Last edited:

1.
refer this

https://www.edaboard.com/threads/263542/

To be more understandable


tclsh filename.tcl a b c

puts "[lindex $argv 0]"
puts "[lindex $argv 1]"
puts "[lindex $argv 2]"

will print a b and c..


2.
if u use set to declare a variable its local u cannot call it in other programs u can pass it as arguments..

3. #!/usr/bin/env

Normally #!/usr/bin will have some necessary builtin functions to use that functions we need to define this....
 

1.
refer this

https://www.edaboard.com/threads/263542/

To be more understandable


tclsh filename.tcl a b c

puts "[lindex $argv 0]"
puts "[lindex $argv 1]"
puts "[lindex $argv 2]"

will print a b and c..

So following commands will collect the arguments in variable1, variable2.

setenv variable1 "[lindex $argv 0]";

setenv variable2 "[lindex $argv 1]" ;

IS NOT IT? Please answer yes or no. This is the answer I wanted. I think above command will have two environment variable named variable1, variable2 containing arg1, arg2 as their contents respectively so that variable1, variable2 can be used in the scripts subsequently. IS NOT IT? Please answer yes or no.

2.
if u use set to declare a variable its local u cannot call it in other programs u can pass it as arguments..

Suppose I have a main script/program which consists of many scripts. Suppose one of this script has variables declared my 'set' command. Can this variables be used from other scripts of the main script/program. So in short the question is: Is it that this local variable can be called from any script out of all scripts that makes the complete program? Please reply.
3. #!/usr/bin/env

Normally #!/usr/bin will have some necessary builtin functions to use that functions we need to define this....

Should we write #!/usr/bin/env tclsh or #!/usr/bin/env at the beginning of the tcl script?
 

1. No your syntax is wrong u cant set envirnonmental variable like this in tclsh

2. no u cant call outside

3. no need.. its not compulsary..
 

1. No your syntax is wrong u cant set envirnonmental variable like this in tclsh

What is the correct syntax then to collect the arguments in a variable for later uses? Can the 'set' command be used instead of 'setenv' iusing my the above similar syntax to collect the arguments?

2. no u cant call outside

But you stated that 'Declaring as variable is local so u cant call outside that specific program'. But here I am stating the I have a program that is build up with many scripts (seven scripts where each of the seven script is kept inside a file). So my program is build up with seven files with each file containing some portions of the main script that makes the main program. In that case suppose one variable is set using 'set' command in one of the files named file1 out of the seven files. Can this variable be used from file named file2 which is one of the files out of the seven file?

3. no need.. its not compulsary..

So what does this tclsh do when we write #!/usr/bin/env tclsh?
 

Hai sunray dont mess up with all the things together..

Do one by one..

yes set command can be used instead.. It will work but its local variable.

Try to pass the variable through command line or through procedures with arguments to share things to other files

Its like stdio.h in c
It will have some buit in function..
 

Try to pass the variable through command line or through procedures with arguments to share things to other files

You did not answer the questions in the following passage. Please answer.

But you stated that 'Declaring as variable is local so u cant call outside that specific program'. But here I am stating the I have a program that is build up with many scripts (seven scripts where each of the seven script is kept inside a file). So my program is build up with seven files with each file containing some portions of the main script that makes the main program. In that case suppose one variable is set using 'set' command in one of the files named file1 out of the seven files. Can this variable be used from file named file2 which is one of the files out of the seven file?

Its like stdio.h in c
It will have some buit in function..

But stdio.h is a compulsory library in C. Is it that tclsh itself a library like stdio.h in C and this tclsh library is not compulsory?
 

i answered to that please crosscheck

Try to pass the variable through command line or through procedures with arguments to share things to other files

let me explain again

if u have seven scripts added to that main script try to pass the variable by arguments instead of seperate code. use like this

tclsh filename.tcl arg1 arg2 arg3 from main file...

no u cant able to access the value of variable in two separate file untill its an environmental variable. if u want to access pass as command line arugments thats it..


u know whats the use of stdio.h its will have input and output function like printf and scanf if ur code doesnt have printf and scanf u dont need stdio.h in c..

likewise here did u used anything specific from #!/usr/bin/env if not then why u r worrying about that........?
 

i

no u cant able to access the value of variable in two separate file untill its an environmental variable. if u want to access pass as command line arugments thats it..

Now you answered my question by providing the above statement.

i
u know whats the use of stdio.h its will have input and output function like printf and scanf if ur code doesnt have printf and scanf u dont need stdio.h in c..

likewise here did u used anything specific from #!/usr/bin/env if not then why u r worrying about that........?

My earlier question was as below
So what does this tclsh do when we write #!/usr/bin/env tclsh?

I wanted to know about putting tclsh in the line #!/usr/bin/env tclsh. Is it that you wanted to mean tclsh as library.
 
Last edited:

Hai sunray,

#!/usr/local/bin/tclsh

but would be non portable as tclsh might be installed in /bin or /bin/local

Using env

#!/usr/bin/env tclsh

is a method allowing a portable way to specify to the OS a full path equivalent to the actual one where tclsh is first located in the PATH.

Inside this it will contains all the files necessary files needed for tclsh


It will mention the tclsh installed path.. pointing to the whole tclsh lib bundle


So it will not have much impact over your code which u wrote inside.. Even if u leave this command it wont hurt u..
 
Last edited:
Hai sunray,

#!/usr/local/bin/tclsh

but would be non portable as tclsh might be installed in /bin or /bin/local

What are you trying to imply/say by writing the above statement?
#!/usr/bin/env tclsh

is a method allowing a portable way to specify to the OS a full path equivalent to the actual one where tclsh is first located in the PATH.

Inside this it will contains all the files necessary files needed for tclsh


It will mention the tclsh installed path.. pointing to the whole tclsh lib bundle


So it will not have much impact over your code which u wrote inside.. Even if u leave this command it wont hurt u..

Is tclsh a library like stdio.h in C? What benefits does tclsh provide if it does not impact even if we do not include tclsh?
 

not exactly like that it will have the path where all necessary files will be there..

To be more understandble we can say it as installed path..

if u include that statement it shows ur installed path is this..

it would be more understandable if u read this.. it shows the usage if u set like this..

**broken link removed**
**broken link removed**
**broken link removed**

go through these three links u will get somewhat what i am coming to say..
 

not exactly like that it will have the path where all necessary files will be there..

To be more understandble we can say it as installed path..

if u include that statement it shows ur installed path is this..

it would be more understandable if u read this.. it shows the usage if u set like this..

**broken link removed**
**broken link removed**
**broken link removed**

go through these three links u will get somewhat what i am coming to say..


But reading the above link I infer it is mandatory to write at the beginning that line. How do you comment that even if that line is not added, it will not harm?
 

acutally u went through that right.., Also there will be lots of options like that did u note that??

but do it pracitally by

running the code with and without that command for a normal tclsh program u will not feel any difference until u dont used some builtin commands..

It will not harm u in any way.. until u use some of the builtin commands..

right....

So it will work fine if u doesnt use this statement..

I have done lots of codes in tcl without this statement and its working fine in all cases...

so u made a way whether u need or not.. Its upto u..
 

acutally u went through that right.., Also there will be lots of options like that did u note that??

.

Which other options are you talking of?

running the code with and without that command for a normal tclsh program u will not feel any difference until u dont used some builtin commands.

Can you please provide some of the build in commands for tcl?
 

In this case Options like

#!/usr/bin/wish
#!/usr/bin/tclshX.Y
#!/usr/bin/wishX.Y
#!/usr/bin/tclsh


etc..,


use based on ur requirements

i not much aware of that inbuilt commands thats why i didnt recommended u.. i will write my own procedure for all cases..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top