View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] non positional argument

From: <vitick_at_gmail.com>
Date: Tue, 26 Oct 2010 14:23:01 -0700 (PDT)

Is it possible to have a non-positional argument that is optional and its variable is only set when it is present as the argument to the method. Otherwise, it is ignored, no error.
Basically, I want it behave like an option to the method but without specifying any value. Example:

myobj method m {-test} {
    if {[info exists test]} {
        puts "test exists";
    } else {
        puts "test does not exist";
    }

myobj m;#test does not exist
myobj m -test;#test exists

Or, it can even be a boolean, set to 1 if it was specified and set to 0 if not. That would be even better, shorter code.

Thank you