From: Zoran V. <zv...@ar...> - 2005-05-26 16:08:27
|
Am 26.05.2005 um 17:41 schrieb Stephen Deasey: > On 5/26/05, Zoran Vasiljevic <zv...@ar...> wrote: > >> Stephen, >> >> Can you please give us some examples how to use the >> ns_parseargs call? I would like to integrate this >> in our code now and would need to instruct all my >> collegues how to use it. >> >> Just a couple of examples would be sufficient. >> >> Thanks >> Zoran >> > > > proc ex1 {args} { > ns_parseargs {-a {-b ""} -- x {y Y} args} $args > > if {[info exists a]} { > return [list $a $b $x $y $args] > } > return [list $b $x $y $args] > } > > > There's some use of ns_parseargs in the nstest_http proc of the test > harness, and of course in ns_parseargs.test. Ah. Good tip. What I was also looking is the usage of "?" in the specstring (never understood this one). So, the "-a" will collect whatever comes after "-a" argument in the arguments list and set the "a" variable to the value. Clear. If I omit "-a" from the argument list, I can use specstring {-a a.default.value} and this will set "a" variable with "a.default.value". Now, where does the "?" come? Also, how do I specify: myproc -booleanarg myarg myproc myarg I'd want to have variable booleanarg set to 1 if i have "-booleanarg" in argument list and set to 0 if I dont. How to specify this (if possible at all; I recall there was an issue with that)? Sorry for all this questions but this lies quite a few weeks since we last talked about it... > > We should probably define ns_proc to allow a more natural usage. I > didn't do that at first as we were discussing extra features such as > type checking. Do you think we can make that backwards compatible? > > proc ns_proc {name spec body} { > proc $name {args} " > ns_parseargs $spec \$args > $body > " > } > > ns_proc ex2 {-a {-b ""} -- x {y Y} args} { > if {[info exists a]} { > return [list $a $b $x $y $args] > } > return [list $b $x $y $args] > } > Hmmm... what do you mean by "backwards compatible"? The ns_proc does not exist, as I see, hence there is no compatibility to look after. We can of course define the ns_proc anytime and it can coexist with the Tcl proc. Did I understand you correctly at all? Apropos type-checking, I would not go to that extent. The number, position and default values of arguments seem pretty fine and sufficient. I would not like to make it more complicated than absolutely necessary. Cheer's Zoran |