Index: doc/next-tutorial.html =================================================================== diff -u -rf41ae7e802868efee95b5d5682edfdbbe9ba2f64 -rf25391601dc81bb54fe227aa5e9341d17de30ae9 --- doc/next-tutorial.html (.../next-tutorial.html) (revision f41ae7e802868efee95b5d5682edfdbbe9ba2f64) +++ doc/next-tutorial.html (.../next-tutorial.html) (revision f25391601dc81bb54fe227aa5e9341d17de30ae9) @@ -734,7 +734,7 @@

The Next Scripting Language (NX) is a highly flexible, Tcl [Ousterhout 1990] based object oriented scripting language. It is a successor of XOTcl 1 [Neumann and Zdun 2000a] and is based on 10 -years of experience with XOTcl in projects containing several hundert +years of experience with XOTcl in projects containing several hundred thousand lines of code. While XOTcl was the first language designed to provide language support for design patterns, the focus of the Next Scripting Framework and NX are on combining this with Language @@ -857,14 +857,14 @@ # Stack of Things # - :variable things {} + :variable things {} - :public method push {thing} { + :public method push {thing} { set :things [linsert ${:things} 0 $thing] return $thing } - :public method pop {} { + :public method pop {} { set top [lindex ${:things} 0] set :things [lrange ${:things} 1 end] return $top @@ -945,7 +945,7 @@ 17 18

#!/bin/env tclsh
-package require nx
+package require nx
 
 nx::Class create Stack {
 
@@ -1042,14 +1042,14 @@
  15
 
nx::Object create stack {
 
-   :variable things {}
+   :variable things {}
 
-   :public method push {thing} {
+   :public method push {thing} {
       set :things [linsert ${:things} 0 $thing]
       return $thing
    }
 
-   :public method pop {} {
+   :public method pop {} {
       set top [lindex ${:things} 0]
       set :things [lrange ${:things} 1 end]
       return $top
@@ -1162,14 +1162,14 @@
   # the methods of class Stack.
   #
 
-  :variable count 0
+  :variable count 0
 
-  :public method push {thing} {
+  :public method push {thing} {
     incr :count
     next
   }
 
-  :public method pop {} {
+  :public method pop {} {
     if {${:count} == 0} then { error "Stack empty!" }
     incr :count -1
     next
@@ -1221,15 +1221,15 @@
  20
  21
  22
-
% package require nx
+
% package require nx
 2.0
 % source Stack.tcl
 ::Stack
 % source Safety.tcl
 ::Safety
 % Stack create s1
 ::s1
-% Stack create s2 -mixin Safety
+% Stack create s2 -mixin Safety
 ::s2
 % s2 push a
 a
@@ -1239,10 +1239,10 @@
 Stack empty!
 
 % s1 info precedence
-::Stack ::nx::Object
+::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 @@ -1295,7 +1295,7 @@ # Create a safe stack class by using Stack and mixin # Safety # -Class create SafeStack -superclass Stack -mixin Safety +Class create SafeStack -superclass Stack -mixin Safety SafeStack create s3

The difference to the case with the per-object mixin is that now, @@ -1353,7 +1353,7 @@ # to check the type of entries # - :public method push {thing:integer} { + :public method push {thing:integer} { next } }

@@ -1392,13 +1392,13 @@ 8 9 10 -
nx::Class create IntegerStack -superclass Stack {
+
nx::Class create IntegerStack -superclass Stack {
 
   #
   # Create a Stack accepting only integers
   #
 
-  :public method push {thing:integer} {
+  :public method push {thing:integer} {
     next
   }
 }
@@ -1463,18 +1463,18 @@ 24
nx::Class create Stack2 {
 
-   :public class method available_stacks {} {
-      return [llength [:info instances]]
+   :public class method available_stacks {} {
+      return [llength [:info instances]]
    }
 
-   :variable things {}
+   :variable things {}
 
-   :public method push {thing} {
+   :public method push {thing} {
       set :things [linsert ${:things} 0 $thing]
       return $thing
    }
 
-   :public method pop {} {
+   :public method pop {} {
       set top [lindex ${:things} 0]
       set :things [lrange ${:things} 1 end]
       return $top
@@ -1568,7 +1568,7 @@
  11
 
Class create Foo {
 
-  :method foo args {...}
+  :method foo args {...}
     # "a" is a method scoped variable
     set a 1
     # "b" is an Instance variable
@@ -1650,17 +1650,17 @@
 # and "birthday"
 #
 nx::Class create Person {
-  :property name:required
-  :property birthday
+  :property name:required
+  :property birthday
 }
 
 #
 # Define a class Student as specialization of Person
 # with additional properties
 #
-nx::Class create Student -superclass Person {
-  :property matnr:required
-  :property {oncampus:boolean true}
+nx::Class create Student -superclass Person {
+  :property matnr:required
+  :property {oncampus:boolean true}
 }
 
 #
@@ -1733,12 +1733,12 @@
  14
  15
 
Class create Base {
-  :variable x 1
+  :variable x 1
   # ...
 }
 
-Class create Derived -superclass Base {
-  :variable y 2
+Class create Derived -superclass Base {
+  :variable y 2
   # ...
 }
 
@@ -1784,15 +1784,15 @@
  19
 
Class create Base2 {
  # ...
- :method init {} {
+ :method init {} {
    set :x 1
    # ....
  }
 }
 
-Class create Derived2 -superclass Base2 {
+Class create Derived2 -superclass Base2 {
  # ...
- :method init {} {
+ :method init {} {
    set :y 2
    next
    # ....
@@ -1860,7 +1860,7 @@
 nx::Class create Dog {
 
   # Define a scripted method for the class
-  :public method bark {} {
+  :public method bark {} {
     puts "[self] Bark, bark, bark."
   }
 }
@@ -1938,13 +1938,13 @@
  24
  25
 
nx::Class create Dog {
- :public method bark {} { puts "[self] Bark, bark, bark." }
- :method init {} { Tail create [self]::tail}
+ :public method bark {} { puts "[self] Bark, bark, bark." }
+ :method init {} { Tail create [self]::tail}
 }
 
 nx::Class create Tail {
-  :property {length:double 5}
-  :public method wag {} {return Joy}
+  :property {length:double 5}
+  :public method wag {} {return Joy}
 }
 
 # Create an instance of the class
@@ -2000,16 +2000,16 @@
  18
  19
 
nx::Class create Dog {
-  :public method bark {} { puts "[self] Bark, bark, bark." }
-  :method init {} {
+  :public method bark {} { puts "[self] Bark, bark, bark." }
+  :method init {} {
     Tail create [self]::tail
-    :public forward wag [self]::tail wag
+    :public forward wag [self]::tail wag
   }
 }
 
 nx::Class create Tail {
-  :property {length 5}
-  :public method wag {} {return Joy}
+  :property {length 5}
+  :public method wag {} {return Joy}
 }
 
 # Create an instance of the class
@@ -2077,10 +2077,10 @@
  12
  13
 
nx::Class create Dog {
-  :public method bark {} { puts "[self] Bark, bark, bark." }
+  :public method bark {} { puts "[self] Bark, bark, bark." }
 
   # Define a public alias for the method "bark"
-  :public alias warn [:info method handle bark]
+  :public alias warn [:info method handle bark]
   # ...
 }
 
@@ -2161,13 +2161,13 @@
 
nx::Class create Foo {
 
   # Define a public method
-  :public method foo {} {
+  :public method foo {} {
     # ....
     return [:helper]
   }
 
   # Define a protected method
-  :method helper {} {
+  :method helper {} {
      return 1
   }
 }
@@ -2214,14 +2214,14 @@
  13
  14
 
nx::Class create Base {
-  :private method helper {a b} {expr {$a + $b}}
-  :public method foo     {a b} {: -local helper $a $b}
+  :private method helper {a b} {expr {$a + $b}}
+  :public method foo     {a b} {: -local helper $a $b}
 }
 
-nx::Class create Sub -superclass Base {
-  :public method bar     {a b} {: -local helper $a $b}
-  :private method helper {a b} {expr {$a * $b}}
-  :create s1
+nx::Class create Sub -superclass Base {
+  :public method bar     {a b} {: -local helper $a $b}
+  :private method helper {a b} {expr {$a * $b}}
+  :create s1
 }
 
 s1 foo 3 4     ;# returns 7
@@ -2280,8 +2280,8 @@
   7
   8
 
nx::Class create C {
-  :public method foo {} {return 1}
-  :create c1
+  :public method foo {} {return 1}
+  :create c1
 }
 
 # Method "foo" is defined on class "C"
@@ -2336,10 +2336,10 @@
  18
  19
 
nx::Class create C {
-  :public method foo {} {return 1}
-  :create c1 {
-     :public method foo {} {return 2}
-     :public method bar {} {return 3}
+  :public method foo {} {return 1}
+  :create c1 {
+     :public method foo {} {return 2}
+     :public method bar {} {return 3}
   }
 }
 
@@ -2351,7 +2351,7 @@
 
 # Method "baz" is an object specific method of "o1"
 nx::Object create o1 {
-  :public method baz {} {return 4}
+  :public method baz {} {return 4}
 }
 o1 baz
@@ -2413,13 +2413,13 @@ # Define a class method "bar" and an instance # method "foo" # - :public class method bar {} {return 2} - :public method foo {} {return 1} + :public class method bar {} {return 2} + :public method foo {} {return 1} # # Create an instance of the current class # - :create c1 + :create c1 } # Method "bar" is a class method of class "C" @@ -2487,11 +2487,11 @@ # Define an ensemble method "string" with sub-methods # "length", "tolower" and "info" - :public method "string length" {x} {....} - :public method "string tolower" {x} {...} - :public method "string info" {x} {...} + :public method "string length" {x} {....} + :public method "string tolower" {x} {...} + :public method "string info" {x} {...} ... - :create c1 + :create c1 } # Invoke the ensemble method @@ -2540,15 +2540,15 @@ 19 20
nx::Class create C {
-  :public method foo {} { return "C foo: [next]"}
+  :public method foo {} { return "C foo: [next]"}
 }
 
-nx::Class create D -superclass C {
+nx::Class create D -superclass C {
 
-  :public method foo {} { return "D foo: [next]"}
+  :public method foo {} { return "D foo: [next]"}
 
-   :create d1 {
-     :public method foo {} { return "d1 foo: [next]"}
+   :create d1 {
+     :public method foo {} { return "d1 foo: [next]"}
    }
 }
 
@@ -2610,10 +2610,10 @@
  23
  24
 
nx::Class create M1 {
-  :public method foo {} { return "M1 foo: [next]"}
+  :public method foo {} { return "M1 foo: [next]"}
 }
 nx::Class create M2 {
-  :public method foo {} { return "M2 foo: [next]"}
+  :public method foo {} { return "M2 foo: [next]"}
 }
 
 #
@@ -2695,7 +2695,7 @@
 current method is defined as a per-object method, foo is resolved as
 a per-object method. The effect is that the mixin definitions are
 ignored. The invocation flag -local was already introduced int the
-setction about method protection, where it was used to call private
+section about method protection, where it was used to call private
 methods.

The invocation flag -intrinsic means that the method has to be resolved from the intrinsic definitions, meaning simply without mixins. The @@ -2816,22 +2816,22 @@ # # Method foo has positional parameters: # - :public method foo {x y} { + :public method foo {x y} { puts "x=$x y=$y" } # # Method bar has non-positional parameters: # - :public method bar {-x -y} { + :public method bar {-x -y} { puts "x=$x y=$y" } # # Method baz has non-positional and # positional parameters: # - :public method baz {-x -y a} { + :public method baz {-x -y a} { puts "x? [info exists x] y? [info exists y] a=$a" } } @@ -2919,15 +2919,15 @@ # Method foo has one required and one optional # positional parameter: # - :public method foo {x:required y:optional} { + :public method foo {x:required y:optional} { puts "x=$x y? [info exists y]" } # # Method bar has one required and one optional # non-positional parameter: # - :public method bar {-x:required -y:optional} { + :public method bar {-x:required -y:optional} { puts "x=$x y? [info exists y]" } } @@ -2996,14 +2996,14 @@ # # Positional parameter with default value: # - :public method foo {x:required {y 101}} { + :public method foo {x:required {y 101}} { puts "x=$x y? [info exists y]" } # # Non-positional parameter with default value: # - :public method bar {{-x 10} {-y 20}} { + :public method bar {{-x 10} {-y 20}} { puts "x=$x y? [info exists y]" } } @@ -3085,14 +3085,14 @@ # # Positional parameter with value constraints: # - :public method foo {x:integer o:object,optional} { + :public method foo {x:integer o:object,optional} { puts "x=$x o? [info exists o]" } # # Non-positional parameter with value constraints: # - :public method bar {{-x:integer 10} {-verbose:boolean false}} { + :public method bar {{-x:integer 10} {-verbose:boolean false}} { puts "x=$x y=$y" } } @@ -3158,7 +3158,7 @@ # # Parameterized value constraints # - :public method work { + :public method work { -person:object,type=Person -project:object,type=Project } { @@ -3272,10 +3272,10 @@ # using the new value checkers # Class create D { - :public method foo {a:groupsize} { + :public method foo {a:groupsize} { # ... } - :public method bar {a:choice,arg=red|yellow|green b:choice,arg=good|bad} { + :public method bar {a:choice,arg=red|yellow|green b:choice,arg=good|bad} { # ... } } @@ -3378,23 +3378,23 @@ # Positional parameter with an possibly empty # single value # - :public method foo {x:integer,0..1} { + :public method foo {x:integer,0..1} { puts "x=$x" } # # Positional parameter with an possibly empty # list of values value # - :public method bar {x:integer,0..n} { + :public method bar {x:integer,0..n} { puts "x=$x" } # # Positional parameter with a non-empty # list of values # - :public method baz {x:integer,1..n} { + :public method baz {x:integer,1..n} { puts "x=$x" } }

@@ -3519,17 +3519,17 @@
# and "birthday" # nx::Class create Person { - :property name:required - :property birthday + :property name:required + :property birthday } # # Define a class Student as specialization of Person # with and additional property # -nx::Class create Student -superclass Person { - :property matnr:required - :property {oncampus:boolean true} +
nx::Class create Student -superclass Person { + :property matnr:required + :property {oncampus:boolean true} } # @@ -3607,12 +3607,12 @@ 8
Object parameter for Person p1:
    -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
 
 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 optained via introspection via Person info parameter definition. The object parameter types mixinreg and filterreg are for converting definitions of filters and mixins. The @@ -3663,8 +3663,8 @@ 2 3

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

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

@@ -3775,8 +3775,8 @@ 8 9 10 -
::nx::Object create o {
-  :method unknown {called_method args} {
+
::nx::Object create o {
+  :method unknown {called_method args} {
     puts "Unknown method '$called_method' called"
   }
 }
@@ -3831,24 +3831,24 @@
  20
  21
  22
-
::nx::Class public class method __unknown {name} {
+
::nx::Class public class method __unknown {name} {
   # A very simple unknown handler, showing just how
   # the mechanism works.
   puts "***** __unknown called with <$name>"
-  ::nx::Class create $name
+  ::nx::Class create $name
 }
 
 # Register an unknown handler as a method of ::nx::Class
-::nsf::object::unknown::add nx {::nx::Class __unknown}
+::nsf::object::unknown::add nx {::nx::Class __unknown}
 
-::nx::Object create o {
+::nx::Object create o {
   # The class M is unknown at this point
 
-  :mixin add M
+  :mixin add M
   # The line above has triggered the unknown class handler,
   # class M is now defined
 
-  puts [:info mixin classes]
+  puts [:info mixin classes]
   # The output will be:
   #     ***** __unknown called with <::M>
   #     ::M
@@ -3959,7 +3959,7 @@