Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy Question

Status
Not open for further replies.

Ati2ude

Programmer
Dec 11, 2001
79
US
I am trying to write a TCL proc and pass a list of args to the proc when it is called, I am not doing something correctly. I have attached my code example and the error I recieve. Any ideas? Thanks in advance.


How I am calling it:
xlt_parse_field "DELIM - MSG 0 STRNUM 0"

Code:
proc xlt_parse_field { args } {
keylget args ARGS.DELIM inDelim
keylget args ARGS.MSG inMSG
keylget args ARGS.STRNUM inStrNum
echo "Delim: $inDelim"
echo "MSG: $inMsg"
echo "StrNum: $inStrNum"
}


Error:
errorInfo:
no value given for parameter "DELIM" to "xlt_parse_field"
while executing
"xlt_parse_field "DELIM - MSG 0 STRNUM 0""
<End of errorInfo>
 
I am using TCL with in a Interface Engine (CloverLeaf).
 
I don't know this tool.
My best guest to help you:
Try
Code:
 xlt_parse_field DELIM - MSG 0 STRNUM 0
(without quotes).

HTH

ulis
 
The proc command can acept a list of arguments, correct? If so, what is the correct format to pass the arguments to the proc?

Thanks for you help thus far.

 
Any argument of a proc can be a list:
Code:
  proc p1 {arg1 listarg}   {
    set var $arg1
    foreach item $listarg { puts $item }
  }
  p1 an_arg [list a list of args]
->a
->list
->of
->args

A special case is the last parameter: if its name is args it collects the last args not already collected in a list:
Code:
  proc p2 {arg1 args}   {
    set var $arg1
    foreach arg $args { ... }
  }
  p2 an_arg a list of args
->a
->list
->of
->args

So: the definition of your proc is correct (you used args to collect all args in the list). The use of your proc is not correct (you used a single string containing all the args in place of letting the args for its own)

More on the proc syntax: (specifically in the section Order of arguments)

HTH

ulis
 
That is what I needed. Thanks for the pointer to that web page, it actually answered my next question on overloading.

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top