Index: TODO =================================================================== diff -u -r5bcfa978f7b42933cd499264abc4679093e8182d -rdc4e18f42355dbf473140da723940832c3aba2ba --- TODO (.../TODO) (revision 5bcfa978f7b42933cd499264abc4679093e8182d) +++ TODO (.../TODO) (revision dc4e18f42355dbf473140da723940832c3aba2ba) @@ -3887,13 +3887,11 @@ - removed documentation about incompatibility to XOTcl1 in respect of the method interface for object invocations +- doc fixed line-number handling locally ======================================================================== TODO: -- why is now "numbers" in asciidoc pretty-print-interface ignored? - [source,tcl,numbers] - (asciidoc has changed from 8.5.5 to 8.5.6) - document new setable object properties perobjectdispatch and keepcallerself - pertaining perobjectdispatch and keepcallerself in serializer Index: doc/next-tutorial.html =================================================================== diff -u -r5bcfa978f7b42933cd499264abc4679093e8182d -rdc4e18f42355dbf473140da723940832c3aba2ba --- doc/next-tutorial.html (.../next-tutorial.html) (revision 5bcfa978f7b42933cd499264abc4679093e8182d) +++ doc/next-tutorial.html (.../next-tutorial.html) (revision dc4e18f42355dbf473140da723940832c3aba2ba) @@ -860,7 +860,26 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
nx::Class create Stack {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+
nx::Class create Stack {
 
    #
    # Stack of Things
@@ -878,7 +897,7 @@
       set :things [lrange ${:things} 1 end]
       return $top
    }
-}
+}

Typically, classes are defined in NX via nx::Class create, followed by the name of the new class (here: Stack). The definition of the stack placed between curly braces and contains here just the method @@ -935,7 +954,25 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

#!/bin/env tclsh
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+
#!/bin/env tclsh
 package require nx
 
 nx::Class create Stack {
@@ -952,7 +989,7 @@
 s1 push c
 puts [s1 pop]
 puts [s1 pop]
-s1 destroy
+s1 destroy

Now we want to use the stack. The code snippet in Listing 3 shows how to use the class Stack in a script. Since NX is based on Tcl, the script will be called with the Tcl shell tclsh. In the Tcl shell we have to require package nx to use the @@ -1017,7 +1054,22 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Object create stack {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+
nx::Object create stack {
 
    :variable things {}
 
@@ -1031,7 +1083,7 @@
       set :things [lrange ${:things} 1 end]
       return $top
    }
-}
+}

The example in Listing 5 defines the object stack in a very similar way as the class Stack. But the following points are different.

@@ -1104,7 +1156,31 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
nx::Class create Safety {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+
nx::Class create Safety {
 
   #
   # Implement stack safety by defining an additional
@@ -1127,7 +1203,7 @@
     incr :count -1
     next
   }
-}
+}

Note that all the methods of the class Safety end with next. This command is a primitive command of NX, which calls the same-named method with the same argument list as the current @@ -1152,7 +1228,29 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

% package require nx
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+
% package require nx
 2.0
 % source Stack.tcl
 ::Stack
@@ -1173,7 +1271,7 @@
 ::Stack ::nx::Object
 
 % s2 info precedence
-::Safety ::Stack ::nx::Object
+::Safety ::Stack ::nx::Object

When the method push of s2 is called, first the method of the mixin class Safety will be invoked that increments the counter and continues with next to call the shadowed method, here the method @@ -1215,13 +1313,20 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

#
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+
#
 # Create a safe stack class by using Stack and mixin
 # Safety
 #
 nx::Class create SafeStack -superclass Stack -mixin Safety
 
-SafeStack create s3
+SafeStack create s3

The difference to the case with the per-object mixin is that now, Safety is mixed into the definition of SafeStack. Therefore, all instances of the class SafeStack (here the instance s3) will be @@ -1259,7 +1364,18 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

Stack create s4 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+
Stack create s4 {
 
   #
   # Create a stack with a object-specific method
@@ -1269,7 +1385,7 @@
   :public method push {thing:integer} {
     next
   }
-}
+}

The program snippet in Listing 12 defines an instance s4 of the class Stack and provides an object specific method for push to implement an integer stack. The method pull is the same for the integer stack @@ -1295,7 +1411,17 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create IntegerStack -superclass Stack {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+
nx::Class create IntegerStack -superclass Stack {
 
   #
   # Create a Stack accepting only integers
@@ -1304,7 +1430,7 @@
   :public method push {thing:integer} {
     next
   }
-}
+}

An alternative approach is shown in Listing 13, where the class IntegerStack is defined, using the same method definition @@ -1341,7 +1467,31 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create Stack2 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+
nx::Class create Stack2 {
 
    :public class method available_stacks {} {
       return [llength [:info instances]]
@@ -1364,7 +1514,7 @@
 Stack2 create s1
 Stack2 create s2
 
-puts [Stack2 available_stacks]
+puts [Stack2 available_stacks]

The class Stack2 in Listing 14 consists of the earlier definition of the class Stack and is extended by the class-specific method available_stacks, which returns the @@ -1435,7 +1585,18 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create Foo {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+
nx::Class create Foo {
 
   :method foo args {...}
     # "a" is a method scoped variable
@@ -1445,7 +1606,7 @@
     # "c" is a global variable/namespaced variable
     set ::c 3
   }
-}
+}

Listing 16 shows a method foo of some class Foo referring to differently scoped variables.

@@ -1489,7 +1650,34 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
#
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+
#
 # Define a class Person with properties "name"
 # and "birthday"
 #
@@ -1515,7 +1703,7 @@
 Student create s1 -name Susan -matnr 4711
 
 # Access property value via accessor method
-puts "The name of s1 is [s1 name]"
+puts "The name of s1 is [s1 name]"

By defining name and birthday as properties of Person, NX provides automatically accessor methods with the same name. The accessors methods (or shortly called "accessors") provide read and @@ -1561,7 +1749,22 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create Base {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+
nx::Class create Base {
   :variable x 1
   # ...
 }
@@ -1575,7 +1778,7 @@
 Derived create d1
 
 # Object d1 has instance variables
-# x == 1 and y == 2
+# x == 1 and y == 2

Note that the variable definitions are inherited in the same way as properties. The example in Listing 19 shows a class Derived that inherits from Base. When an instance d1 is @@ -1592,7 +1795,26 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create Base2 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+
nx::Class create Base2 {
  # ...
  :method init {} {
    set :x 1
@@ -1610,7 +1832,7 @@
 }
 
 # Create instance of the class Derived2
-Derived2 create d2
+Derived2 create d2

In many other object oriented languages, the instance variables are initialized solely by the constructor (similar to class Derived2 in Listing 20). This approach is certainly @@ -1652,7 +1874,21 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

# Define a class
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+
# Define a class
 nx::Class create Dog {
 
   # Define a scripted method for the class
@@ -1665,7 +1901,7 @@
 Dog create fido
 
 # The following line prints "::fido Bark, bark, bark."
-fido bark
+fido bark

In the example above we create a class Dog with a scripted method named bark. The method body defines the code, which is executed when the method is invoked. In this example, the method bar prints out a @@ -1711,7 +1947,32 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create Dog {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+
nx::Class create Dog {
  :public method bark {} { puts "[self] Bark, bark, bark." }
  :method init {} { Tail create [self]::tail}
 }
@@ -1735,7 +1996,7 @@
 fido::tail length 10
 
 # Proving an invalid values will raise an error
-fido::tail length "Hello"
+fido::tail length "Hello"

Listing 22 shows an extended example, where every dog has a tail. The object tail is created as a subobject of the dog in the constructor init. The subobject can be accessed by providing the @@ -1755,7 +2016,26 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create Dog {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+
nx::Class create Dog {
   :public method bark {} { puts "[self] Bark, bark, bark." }
   :method init {} {
     Tail create [self]::tail
@@ -1773,7 +2053,7 @@
 
 # The invocation of "fido wag" is delegated to "fido::tail wag".
 # Therefore, the following method returns "Joy".
-fido wag
+fido wag

Listing 23 again extends the example by adding a forwarder named wag to the object (e.g. fido). The forwarder redirects all calls of the form fido wag with arbitrary arguments to @@ -1819,7 +2099,20 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create Dog {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+
nx::Class create Dog {
   :public method bark {} { puts "[self] Bark, bark, bark." }
 
   # Define a public alias for the method "bark"
@@ -1831,7 +2124,7 @@
 Dog create fido
 
 # The following line prints "::fido Bark, bark, bark."
-fido warn
+fido warn

Listing 24 extends the last example by defining an alias for the method "bark". The example only shows the bare mechanism. In general, method aliases are very powerful means for @@ -1879,7 +2172,29 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create Foo {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+
nx::Class create Foo {
 
   # Define a public method
   :public method foo {} {
@@ -1900,7 +2215,7 @@
 f1 foo
 
 # The invocation of the protected method "helper" raises an error:
-f1 helper
+f1 helper

The example above uses :protected method helper …. We could have used here as well :method helper …, since the default method call-protection is already protected.

@@ -1920,7 +2235,21 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
nx::Class create Base {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+
nx::Class create Base {
   :private method helper {a b} {expr {$a + $b}}
   :public method foo     {a b} {: -local helper $a $b}
 }
@@ -1933,7 +2262,7 @@
 
 s1 foo 3 4     ;# returns 7
 s1 bar 3 4     ;# returns 12
-s1 helper 3 4  ;# raises error: unable to dispatch method helper
+s1 helper 3 4 ;# raises error: unable to dispatch method helper

The base class implements a public method foo using the helper method named helper. The derived class implements a as well a public method bar, which is also using a helper method named helper. When @@ -1977,14 +2306,22 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create C {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+
nx::Class create C {
   :public method foo {} {return 1}
   :create c1
 }
 
 # Method "foo" is defined on class "C"
 # and applicable to the instances of "C"
-c1 foo
+c1 foo

There are many programming languages that only allow these types of methods. However, NX also allows methods to be defined on objects.

@@ -2014,7 +2351,26 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
nx::Class create C {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+
nx::Class create C {
   :public method foo {} {return 1}
   :create c1 {
      :public method foo {} {return 2}
@@ -2032,7 +2388,7 @@
 nx::Object create o1 {
   :public method baz {} {return 4}
 }
-o1 baz
+o1 baz

3.4.3. Class Methods

@@ -2062,7 +2418,32 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
nx::Class create C {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+
nx::Class create C {
   #
   # Define a class method "bar" and an instance
   # method "foo"
@@ -2086,7 +2467,7 @@
 
 # When trying to invoke the class method on the
 # instance, an error will be raised.
-c1 bar
+c1 bar

In some other object oriented programming languages, class methods are called "static methods".

@@ -2122,7 +2503,21 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
nx::Class create C {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+
nx::Class create C {
 
     # Define an ensemble method "string" with sub-methods
     # "length", "tolower" and "info"
@@ -2135,7 +2530,7 @@
 }
 
 # Invoke the ensemble method
-c1 string length "hello world"
+c1 string length "hello world"

3.6. Method Resolution

@@ -2159,7 +2554,27 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
nx::Class create C {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+
nx::Class create C {
   :public method foo {} { return "C foo: [next]"}
 }
 
@@ -2178,7 +2593,7 @@
 
 # Query the precedence order from NX via introspection
 d1 info precedence
-# result: "::D ::C ::nx::Object"
+# result: "::D ::C ::nx::Object"

Consider the example in foo is invoked on object d1, the per-object method has the highest precedence and is therefore invoked. The per-object methods shadows @@ -2205,7 +2620,31 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Class create M1 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+
nx::Class create M1 {
   :public method foo {} { return "M1 foo: [next]"}
 }
 nx::Class create M2 {
@@ -2228,7 +2667,7 @@
 
 # Query the precedence order from NX via introspection
 d1 info precedence
-# result: "::M1 ::M2 ::D ::C ::nx::Object"
+# result: "::M1 ::M2 ::D ::C ::nx::Object"

an extension of the previous example. We define here two additional classes M1 and M2 which are used as per-object and per-class mixins. Both classes define the method foo, these methods shadow @@ -2247,7 +2686,23 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

#
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+
#
 # "d1" is created based on the definitions of the last two examples,
 # the mixins "M1" and "M2" are registered.
 #
@@ -2262,7 +2717,7 @@
 }
 
 # Invoke the method "bar"
-d1 bar
+d1 bar

In the first line of the body of method bar, the method foo is called as usual with an implicit receiver, which defaults to the current object (therefore, the call is equivalent to d1 foo). The @@ -2355,7 +2810,43 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Object create o1 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+
nx::Object create o1 {
 
   #
   # Method foo has positional parameters:
@@ -2390,7 +2881,7 @@
 # invoke baz (positional and non-positional parameters)
 o1 baz -x 1 100
 o1 baz 200
-o1 baz -- -y
+o1 baz -- -y

Consider the example in Listing 34. The method foo has the argument list x y. This means that the first argument is passed in an invocation like o1 foo 1 2 to x (here, the value @@ -2436,7 +2927,28 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Object create o2 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+
nx::Object create o2 {
 
   #
   # Method foo has one required and one optional
@@ -2456,7 +2968,7 @@
 }
 
 # invoke foo (one optional positional parameter is missing)
-o2 foo 1
+o2 foo 1

The example in Listing 35 defined method foo with one required and one optional positional parameter. For this purpose we use the parameter options required and optional. The @@ -2494,7 +3006,27 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Object create o3 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+
nx::Object create o3 {
 
   #
   # Positional parameter with default value:
@@ -2513,7 +3045,7 @@
 
 # use default values
 o3 foo
-o3 bar
+o3 bar

In order to define a default value, the parameter specification must be of the form of a 2 element list, where the second argument is the default value. See for an example in @@ -2564,7 +3096,26 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Object create o4 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+
nx::Object create o4 {
 
   #
   # Positional parameter with value constraints:
@@ -2582,7 +3133,7 @@
 }
 
 # The following invocation raises an exception
-o4 foo a
+o4 foo a

Value contraints are specified as parameter options in the parameter specifications. The parameter specification x:integer defines x as a required positional parmeter which value is constraint to an @@ -2604,7 +3155,35 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

#
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+
#
 # Create classes for Person and Project
 #
 nx::Class create Person
@@ -2631,7 +3210,7 @@
 #
 # Use method with value constraints
 #
-o5 work -person gustaf -project nx
+o5 work -person gustaf -project nx

The native checkers object, class, metaclass and baseclass can be further specialized with the parameter option type to restrict the permissible values to instances of certain classes. We can use for @@ -2665,7 +3244,47 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

#
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+
#
 # Value checker named "groupsize"
 #
 ::nx::Slot method type=groupsize {name value} {
@@ -2704,7 +3323,7 @@
 
 # testing "choice"
 d1 bar green good
-d1 bar pink bad
+d1 bar pink bad

In order to define a checker groupsize a method of the name type=groupsize is defined. This method receives two arguments, name and value. The first argument is the name of the parameter @@ -2762,7 +3381,33 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

nx::Object create o6 {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+
nx::Object create o6 {
 
   #
   # Positional parameter with an possibly empty
@@ -2787,7 +3432,7 @@
   :public method baz {x:integer,1..n} {
     puts "x=$x"
   }
-}
+}

Listing 41 contains three examples for positional parameters with different multiplicities. Multiplicity is often combined with value constraints. A parameter specification of @@ -2877,7 +3522,34 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

#
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+
#
 # Define a class Person with properties "name"
 # and "birthday"
 #
@@ -2903,7 +3575,7 @@
 Student create s1 -name Susan -matnr 4711
 
 # Access property value via accessor method
-puts "The name of s1 is [s1 name]"
+puts "The name of s1 is [s1 name]"

The class Person has two properties name and birthday, where the property name is required, the property birthday is not. The class Student is a subclass of Person with the additional required @@ -2960,14 +3632,22 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

Object parameter for Person p1:
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+
Object parameter for Person p1:
    -name:required -birthday ...
    -mixin:mixinreg,alias,1..n -filter:filterreg,alias,1..n _:initcmd,optional
 
 Object parameter for Student s1:
    -matnr:required {-oncampus:boolean true}
    -name:required -birthday ...
-   -mixin:mixinreg,alias,1..n -filter:filterreg,alias,1..n _:initcmd,optional
+ -mixin:mixinreg,alias,1..n -filter:filterreg,alias,1..n _:initcmd,optional

The actual values can be obtained via introspection via Person info parameter definition. The object parameter types mixinreg and filterreg are for converting definitions of filters and mixins. The @@ -3014,9 +3694,12 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

Object parameter for Class Student:
+
  1
+  2
+  3
+
Object parameter for Class Student:
    -mixin:mixinreg,alias,1..n -filter:filterreg,alias,1..n ...
-   {-superclass:class,alias,1..n ::nx::Object} ...
+ {-superclass:class,alias,1..n ::nx::Object} ...

The actual values can be obtained via introspection via nx::Class info parameter definition.

@@ -3117,7 +3800,17 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
::nx::Object create o {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+
::nx::Object create o {
   :method unknown {called_method args} {
     puts "Unknown method '$called_method' called"
   }
@@ -3126,7 +3819,7 @@
 # Invoke an unknown method for object o:
 o foo 1 2 3
 
-# Output will be: "Unknown method 'foo' called"
+# Output will be: "Unknown method 'foo' called"

Without any provision of an unknown method handler, an error will be raised, when an unknown method is called.

@@ -3151,7 +3844,29 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
::nx::Class public class method __unknown {name} {
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+
::nx::Class public class method __unknown {name} {
   # A very simple unknown handler, showing just how
   # the mechanism works.
   puts "***** __unknown called with <$name>"
@@ -3172,7 +3887,7 @@
   # The output will be:
   #     ***** __unknown called with <::M>
   #     ::M
-}
+}

The Next Scripting Framework allows to add, query, delete and list unknown handlers.

Listing 49: Unknown Handler registration

@@ -3186,11 +3901,16 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
# Interface for unknown handlers:
+
  1
+  2
+  3
+  4
+  5
+
# Interface for unknown handlers:
 # nsf::object::unknown::add /key/ /handler/
 # nsf::object::unknown::get /key/
 # nsf::object::unknown::delete /key/
-# nsf::object::unknown::keys
+# nsf::object::unknown::keys
References
  • @@ -3274,7 +3994,7 @@

    Index: doc/next-tutorial.txt =================================================================== diff -u -r9d8cfca98a5da22ca842502f73d2e6195582dfee -rdc4e18f42355dbf473140da723940832c3aba2ba --- doc/next-tutorial.txt (.../next-tutorial.txt) (revision 9d8cfca98a5da22ca842502f73d2e6195582dfee) +++ doc/next-tutorial.txt (.../next-tutorial.txt) (revision dc4e18f42355dbf473140da723940832c3aba2ba) @@ -345,7 +345,7 @@ [[xmp-class-safety]] .Listing {counter:figure-number}: Class Safety {set:xmp-class-safety:Listing {figure-number}} -[source,tcl,numbers] +[source,tcl,numbered] -------------------------------------------------- nx::Class create Safety {