|
ad_proc Define a procedure
package require nstcl-core ?1.0?
package require nstcl ?1.0?::nstcl::ad_proc ?
-public ? ?-private ? ?-deprecated ? ?-warn ?arg_list ?documentation ?code
ad_proc is an enhancement over Tcl's built-in proc command that supports several types of switches in the arg_list (along with all the types supported by proc).Types of args understood by proc:
- foo
- Single variable foo.
- {args}
- Special args variable that collects all remaining arguments into a list when specified as the last argument.
- {foo bar}
- Multiple variables, foo and bar.
- {foo {bar baz}}
- One required variable foo, and an optional variable bar that will default to a value of baz if another value is not provided.
- {foo {bar baz} args}
- One required variable, an optional variable with a default, and args as a catch-all.
Additional types understood by ad_proc:
- -foo:boolean
- An optional switch foo; a local variable named foo_p will be set to 1 if this switch was present, 0 otherwise.
- -bar:required
- A required switch bar; a local variable named bar will be set. An error is thrown if the procedure is invoked without specifying a value for this switch.
- {-baz default}
- An optional switch baz. If the switch is specified the local variable baz is set to the specified value, otherwise the local variable baz will be set to default.
- -zab:optional
- An optional switch zab. The local variable zab will be set only if specified by the caller; otherwise, the variable will not exist.
Switch parameters must be listed first before any positional parameters. When invoking a procedure which has optional switches, and there is a possibility that the first positional parameter may begin with a hyphen, use "--" to indicate that there are no more switches to parse.
- -public
- Use when the procedure is part of a public API.
- -private
- Use when the procedure is private.
- -deprecated
- Used to indicate that the procedure should no longer be used.
- -warn
- Used to indicate that a warning should be emited when the procedure is invoked.
ad_arg_parser
nstcl