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

Re: [Xotcl] nx attribute predefined value constrains, two more possible options?

From: Gustaf Neumann <>
Date: Wed, 27 Oct 2010 09:11:21 +0200

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'