Forum OpenACS Development: Re: ad_proc - Behaviour using named parameters

Posted by Gustaf Neumann on
The behavior is not unexpected. Since a while, OpenAcs uses the c-implemented argument parser of xotcl2/nsf, when it is installed. This argument parser is many times faster than the old tcl-only implementation (for longer argument lists) and uses less memory. The c-based parser follows the standard tcl mechanisms for parsing options, which may be abbreviated, as long as the abbreviation is unambiguous (see e.g. [1,2]).

The observed behavior above has nothing to do with the "_p" magic of boolean switches in OpenACS, but it is just about abbreviations. In the following code, two switches are provided stating with the same prefix. As long the provide abbreviation is unique, the abbreviation is accepted.

ad_proc -public test_par {
    { -foooo 1 }
    { -foo2  1 }
} {
} {
   return $foooo
ns_return 200 text/html [test_par -foo 2]
In the call in the last line the abbreviation is not unique, therefore an exception with the message "the provided argument -foo is an abbreviation for -foooo and -foo2" is raised.

Abbreviations do not harm the code: all calls which are valid without abbreviations are as well valid with abbreviations, since the variable names are always the full names. The c-based argument parser supports as well more functionality like configurable value checking (providing more safety), but that is not used in OpenACS.


[1] Abbreviations in tk
[2] Tcl library function

Posted by Klaus Hofeditz on
Thanks for your exhaustive and detailed response. It's very much appreciated!