[Xotcl] non positional argument

Victor Mayevski vitick at gmail.com
Thu Oct 28 00:48:32 CEST 2010


Excellent, exactly what I needed. 

Thank you


----- Original Message -----
From: "Gustaf Neumann" <neumann at wu-wien.ac.at>
To: xotcl at alice.wu-wien.ac.at
Sent: Tuesday, October 26, 2010 11:53:26 PM GMT -08:00 US/Canada Pacific
Subject: Re: [Xotcl] non positional argument

On 26.10.10 23:23, vitick at gmail.com wrote:
> 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.
...
> 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.
see below for some optional argument handling. i guess you 
want m2.
-gustaf neumann

=====================================
Object create myobj {
   :public method m1 {-test} {
     puts "m1 test exists [info exists test]"
   }
   :public method m2 {-test:switch} {
     puts "m2 test exists [info exists test] value $test"
   }
   :public method m3 {test:optional} {
     puts "m3 test exists [info exists test]"
   }
}

myobj m1
myobj m1 -test 1
myobj m2
myobj m2 -test
myobj m3
myobj m3 1
=====================================

output is

=====================================
m1 test exists 0
m1 test exists 1
m2 test exists 1 value 0
m2 test exists 1 value 1
m3 test exists 0
m3 test exists 1
=====================================

_______________________________________________
Xotcl mailing list
Xotcl at alice.wu-wien.ac.at
http://alice.wu-wien.ac.at/mailman/listinfo/xotcl


More information about the Xotcl mailing list