I was reading the migration guide, and at the end it talk about the incompatibilities. I have specifically tested the "Calling objects like methods" and I do not understand it. It just doesn't work right. Example:
Object create a; Object create a::b
a public method tst args {puts [self]}; a::b public method tst args {puts [self]};
a tst; #works, returns ::a a::b tst; #error, invalid command self
a::b eval self; #works, returns ::a::b
Thanks
How about adding two move predefined constrains?:
:attribute a:regexp={myregexp} :attribute a:glob={myglob}
Thanks
On 26.10.10 22:58, Victor Mayevski wrote:
How about adding two move predefined constrains?:
:attribute a:regexp={myregexp} :attribute a:glob={myglob}
one can do this with a few lines of code (see below). In most cases, it is better to name the types (like e.g. a type isbn), such that the matching pattern/regexp does not have to be repeated on each usage.
-gustaf neumann
============================================== ::nx::Slot method type=glob {name value pattern} { if {![string match $pattern $value]} { error "Value '$value' does not match pattern '$pattern'" } }
Class create C { :attribute x:glob,arg=*world :public method foo {a:glob,arg=*x b:glob,arg=*y} { return $a-$b } }
#C create c1 -x abc; #Error: Value 'abc' does not match pattern '*world' C create c2 -x "hello world" c2 foo xxx yyy #c2 foo x aya; #Error: Value 'aya' does not match pattern '*y'
Very nice. It is even better than I thought. ::Slot has been probably the most confusing part of XOTcl for me, hence I only used it for Attribute.
Thanks
----- Original Message ----- From: "Gustaf Neumann" neumann@wu-wien.ac.at To: "Victor Mayevski" vitick@gmail.com Cc: xotcl@alice.wu-wien.ac.at Sent: Wednesday, October 27, 2010 12:11:21 AM GMT -08:00 US/Canada Pacific Subject: Re: nx attribute predefined value constrains, two more possible options?
On 26.10.10 22:58, Victor Mayevski wrote:
How about adding two move predefined constrains?:
:attribute a:regexp={myregexp} :attribute a:glob={myglob}
one can do this with a few lines of code (see below). In most cases, it is better to name the types (like e.g. a type isbn), such that the matching pattern/regexp does not have to be repeated on each usage.
-gustaf neumann
============================================== ::nx::Slot method type=glob {name value pattern} { if {![string match $pattern $value]} { error "Value '$value' does not match pattern '$pattern'" } }
Class create C { :attribute x:glob,arg=*world :public method foo {a:glob,arg=*x b:glob,arg=*y} { return $a-$b } }
#C create c1 -x abc; #Error: Value 'abc' does not match pattern '*world' C create c2 -x "hello world" c2 foo xxx yyy #c2 foo x aya; #Error: Value 'aya' does not match pattern '*y'
Not sure, what's wrong on your side. i can't see a problem with this code, and it works for me.
-gustaf
% Object create a ::a % Object create a::b ::a::b % a public method tst args {puts [self]}; ::a::tst % a::b public method tst args {puts [self]}; ::a::b::tst % a tst ::a % a::b tst ::a::b %
On 26.10.10 22:47, vitick@gmail.com wrote:
I was reading the migration guide, and at the end it talk about the incompatibilities. I have specifically tested the "Calling objects like methods" and I do not understand it. It just doesn't work right. Example:
Object create a; Object create a::b
a public method tst args {puts [self]}; a::b public method tst args {puts [self]};
a tst; #works, returns ::a a::b tst; #error, invalid command self
a::b eval self; #works, returns ::a::b
Thanks _______________________________________________ Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl