Tcl Script Learning 11: Proc Application (with default parameters)

Source: Internet
Author: User

Lesson 11:proc application (with default parameters)


1.//all parameter values are not necessarily entered when using the process. The input parameters of the procedure can have default values. The default value is determined by
{Default parameter name default} specified. If the procedure is called without specifying the values of these parameters, its default value is used.
Otherwise, use the input values to override the default values. When using default parameters, be aware that if the default parameters are followed by a
Non-default parameter, the value of the default parameter also requires input when this procedure is called, or an error occurs. This is because
When calling a procedure for TCL, the parameters and input values are matched according to the location.
2. If the last parameter in the argument list is args, the procedure can receive a variable number of input parameters. When a call has been
Parameter values other than the specified parameters are received by args. If only the args item is in the argument list, the args connection
Accept all input parameter values

Example①: The use of the return value of the calling function

Proc Test {a {b 7} {str "Hello World"}} {
Puts "$str"
return [expr $a * $b]
}

Puts "[Test 7 7]"


Example②:

Proc Test {args} {
Puts "input values are: $args"
}

Test my name is Zhouli

Result:input values Are:my name is Zhouli
To verify the beginning of the 2nd Word.

Example③:

Proc Config_sys {args} {
Array Set Inarr $args
Parray Inarr
}

Config_sys-sysname "HUB100"-ipaddr 192.168.10.1-date 2003-11-21-time 21:03:45


Result:
Inarr (-date) = 2003-11-21
Inarr (-ipaddr) = 192.168.10.1
Inarr (-sysname) = HUB100
Inarr (-time) = 21:03:45

Put it on first.


Go to this lesson!! Cough cough

Proc Example {first {second ""} args} {
if {$second = = ""} {
Puts "There is only one argument and it is: $first";
return 1;
} else {
if {$args = = ""} {
Puts "There is arguments-$first and $second";
return 2;
} else {
Puts "There is many arguments-$first and $second and $args";
return "many";
}
}
}

Set COUNT1 [Example one]
Set Count2 [Example one]
Set COUNT3 [Example one, three]
Set COUNT4 [Example one, three four]
Examples combine a lot of simple usages, not explanations

Tcl Script Learning 11: Proc Application (with default parameters)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.