Index: TODO =================================================================== diff -u -rbb18837f55b64ecdaf970c9e77624bc30f4c417a -r09fdaef530d334f8ea065db60b20a644c671e74d --- TODO (.../TODO) (revision bb18837f55b64ecdaf970c9e77624bc30f4c417a) +++ TODO (.../TODO) (revision 09fdaef530d334f8ea065db60b20a644c671e74d) @@ -2038,12 +2038,14 @@ - further cleanup of error procs: eliminated NsfObjErrArgCnt() - improve error message, when too many arguments are passed +- extended und overworked mirgration guide (added e.g. multiplicity) +- extended regression test + TODO: - "-returns" * handle "-returns" in serializer -- change allowempty to "empty" - check performance implications of value conflict checker - extend coro regression test Index: doc/next-migration.html =================================================================== diff -u -r3d40cb4ba41cd488a5095695d7dcd8a6bd69efa9 -r09fdaef530d334f8ea065db60b20a644c671e74d --- doc/next-migration.html (.../next-migration.html) (revision 3d40cb4ba41cd488a5095695d7dcd8a6bd69efa9) +++ doc/next-migration.html (.../next-migration.html) (revision 09fdaef530d334f8ea065db60b20a644c671e74d) @@ -784,7 +784,7 @@ Stack instproc pop {} { my instvar things set top [lindex $things 0] - set things [lrange $things 1 end] + set things [lrange $things 1 end] } @@ -1579,8 +1579,18 @@ + +
+

3.4. Parameters

+

While XOTcl 1 had very limited forms of parameters, XOTcl 2 and nx +provide a generalized and highly orthogonal parameter handling with +various kinds of value constraints. We devide the parameters into +Object Parameters (parameters used for initializing objects and +classes) and Method Parameters (parameters passed to +methods). Furthermore, XOTcl 2 and NX support return value checker +based on the same mechanisms.

-

3.3.4. Object Parameters/Attributes

+

3.4.1. Object Parameters

-
Class Foo -parameter {a {b 1}}
+
# Object parameter specified as a list (short form)
+# "a" has no default, "b" has default "1"
 
+Class Foo -parameter {a {b 1}}
+
 # Create instance of the class Foo
 Foo f1 -a 0
 
-# Object f1 has a == 0 and b == 1
-
+# Object f1 has a == 0 and b == 1
+ +# Object f1 has a == 0 and b == 1 + + + @@ -1748,39 +1786,182 @@ by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> -
# Multivalued parameter not available
+
# Multiplicity for parameter not available
-
Class Foo -slots {
-   Attribute a
-   Attribute b -default 1
-}
+
# Object parameter specified as a list (short form)
+# "a" has no default, "b" has default "1"
 
+Class create Foo -attributes {a {b 1}}
+
 # Create instance of the class Foo
-Foo f1 -a 0
+Foo create f1 -a 0
 
-# Object f1 has a == 0 and b == 1
-
-
Class create Foo -attributes {a {b 1}}
+
# Object parameter specified via slots
 
+Class Foo -slots {
+   Attribute a
+   Attribute b -default 1
+}
+
 # Create instance of the class Foo
-Foo create f1 -a 0
+Foo f1 -a 0
 
-# Object f1 has a == 0 and b == 1
-
+# Object f1 has a == 0 and b == 1 +
-
Class create Foo {
+
# Object parameter specified via attribute methods
+# (allow method modifieres and scripted configuration)
+
+Class create Foo {
    :attribute a
    :attribute {b 1}
 }
@@ -1654,7 +1677,10 @@
 by Lorenzo Bettini
 http://www.lorenzobettini.it
 http://www.gnu.org/software/src-highlite -->
-
Class Person -slots {
+
# Object parameter with configured slot, defining an attribute
+# specific type checker
+
+Class Person -slots {
    Attribute create sex -type "sex" {
      my proc type=sex {name value} {
        switch -glob $value {
@@ -1670,7 +1696,10 @@
 by Lorenzo Bettini
 http://www.lorenzobettini.it
 http://www.gnu.org/software/src-highlite -->
-
Class create Person {
+
# Object parameter with scripted definition, defining an attribute
+# specific type checker
+
+Class create Person {
    :attribute sex {
      :type "sex"
      :method type=sex {name value} {
@@ -1695,10 +1724,16 @@
 by Lorenzo Bettini
 http://www.lorenzobettini.it
 http://www.gnu.org/software/src-highlite -->
-
# Predefined value constraints: object, class, alnum, alpha,
-# ascii, boolean, control, digit, double, false, graph,
-# integer, lower, print, punct, space, true, upper,
-# wordchar, xdigit
+
# Predefined value constraints:
+#    object, class, alnum, alpha, ascii, boolean, control,
+#    digit, double, false, graph, integer, lower, print,
+#    punct,  space, true, upper, wordchar, xdigit
+#
+# User defined value constraints are possible.
+# All parameter value checkers can be turned on and off.
+#
+# Define a boolean attribute and an integer attribute with a
+# default
 
 Class create Foo -attributes {
    a:boolean
@@ -1726,10 +1761,13 @@
 by Lorenzo Bettini
 http://www.lorenzobettini.it
 http://www.gnu.org/software/src-highlite -->
-
# Required parameter
+
# Required parameter:
+# Define a required attribute a and a required boolean
+# attribute b
+
 Class create Foo -attributes {
-   a:boolean,required
-   {b:integer 1}
+   a:required
+   b:boolean,required
 }

 Class create Foo {
-   :attribute a:boolean,required
-   :attribute {b:integer 1}
+   :attribute a:required
+   :attribute b:boolean,required
 }
-
# Required parameter
+
# Parameter with multiplicity
+
 Class create Foo -attributes {
-   ...
-   ints:integer,multivalued
-   {objs:object,multivalued ""}
+  {ints:integer,0..n ""} ;# list of integers, with default
+   objs:object,1..n       ;# non-empty list of objects
+   obj:object,0..1        ;# single object, maybe empty
 }
Class create Foo {
-   ...
-   :attribute ints:integer,multivalued
-   :attribute {objs:object,multivalued ""}
+  :attribute {ints:integer,0..n ""}
+   :attribute objs:object,1..n
+   :attribute obj:object,0..1
 }
-

## allowempty

+
+

3.4.2. Method Parameters

+

The method parameters specifications in XOTcl 1 were limited and +allowed only value constraints for non positional arguments. NX and +XOTcl 2 provide value constraints for all kind of method parameters. +While XOTcl 1 required non-positional arguments to be listed in front of +positional arguments, this limitation is lifted in XOTcl 2.

+
+ +++ + + + + + + + + + + + + + + + +
XOTcl Next Scripting Language
+
+
# Define method foo with non-positional parameters
+# (x, y and y) and positional parameter (a and b)
+
+Class C
+C instproc foo {-x:integer -y:required -z a b} {....}
+C create c1
+
+# invoke method foo
+c1 foo -x 1 -y a 2 3
+
+
# Define method foo with non-positional parameters
+# (x, y and y) and positional parameter (a and b)
+
+Class create C {
+   :public method foo {-x:integer -y:required -z a b} {....}
+   :create c1
+}
+# invoke method foo
+c1 foo -x 1 -y a 2 3
+
+
# n.a.
+
+
# Define various forms of parameters not available in XOTcl 1
+
+Class create C {
+   # trailing (or interleaved) non-positional parameters
+   :public method m1 {a b -x:integer -y} {....}
+
+   # postional parameters with value constraints
+   :public method m2 {a:integer b:boolean} {....}
+
+   # optional postional parameter (trailing)
+   :public method set {varName value:optional} {....}
+
+   # parameter with multiplicty
+   :public method m3 {-objs:object,1..n c:class,0..1} {....}
+
+   # In general, the same list of value constraints as for
+   # object parameter is available (see above).
+   #
+   # User defined value constraints are possible.
+   # All parameter value checkers can be turned on and off.
+}
-
-

3.4. Method Parameters

-

todo

+
+

3.4.3. Return Value Checkers

+

Return value checker are a functionality that was not yet available in +XOTcl 1. A return value checker assures that a method returns always a +parameter of a certain value. Return value checkers can be defined on +all forms of methods. Like for other value checkers, return +value checkers can be turned on and off.

+
+ +++ + + + + + + + + + + + +
XOTcl Next Scripting Language
+
+
# n.a.
+
+
# Define method foo with non-positional parameters
+# (x, y and y) and positional parameter (a and b)
+
+Class create C {
+   # Define method foo which returns an integer value
+   :method foo -returns integer {-x:integer} {....}
+
+   # Define an alias for the Tcl command ::incr
+   # and assure, it always returns in integer
+   :alias incr -returns integer ::incr
+
+   # Define a forwarder that has to return integer
+   :forward ++ -returns integer ::expr 1 +
+
+  # Define a method that has to return a non-empty
+  # list of objects
+  :public class-object method instances {} -returns object,1..n {
+    return [:info instances]
+   }
+}
+
+
+

3.5. Interceptors

@@ -3599,7 +3780,7 @@ replaced.

-

4.2. Parameters

+

4.2. Parameters

The following changes for parameters could be regarded as bug-fixes.

4.2.1. Parameter usage without a value

@@ -3688,7 +3869,7 @@ Index: doc/next-migration.txt =================================================================== diff -u -rf9bd043ef944ad48d9d626408d25d8df241d834d -r09fdaef530d334f8ea065db60b20a644c671e74d --- doc/next-migration.txt (.../next-migration.txt) (revision f9bd043ef944ad48d9d626408d25d8df241d834d) +++ doc/next-migration.txt (.../next-migration.txt) (revision 09fdaef530d334f8ea065db60b20a644c671e74d) @@ -712,23 +712,51 @@ ---------------- |====================== -==== Object Parameters/Attributes +=== Parameters +While XOTcl 1 had very limited forms of parameters, XOTcl 2 and nx +provide a generalized and highly orthogonal parameter handling with +various kinds of value constraints. We devide the parameters into +_Object Parameters_ (parameters used for initializing objects and +classes) and _Method Parameters_ (parameters passed to +methods). Furthermore, XOTcl 2 and NX support return value checker +based on the same mechanisms. + +==== Object Parameters + [options="header",cols="asciidoc,asciidoc",frame="none",valign="middle"] |====================== |XOTcl |Next Scripting Language |[source,tcl] ---------------- +# Object parameter specified as a list (short form) +# "a" has no default, "b" has default "1" + Class Foo -parameter {a {b 1}} # Create instance of the class Foo Foo f1 -a 0 # Object f1 has a == 0 and b == 1 ---------------- -[source,tcl] +|[source,tcl] ---------------- +# Object parameter specified as a list (short form) +# "a" has no default, "b" has default "1" + +Class create Foo -attributes {a {b 1}} + +# Create instance of the class Foo +Foo create f1 -a 0 + +# Object f1 has a == 0 and b == 1 +---------------- + +|[source,tcl] +---------------- +# Object parameter specified via slots + Class Foo -slots { Attribute a Attribute b -default 1 @@ -740,17 +768,12 @@ # Object f1 has a == 0 and b == 1 ---------------- + |[source,tcl] ---------------- -Class create Foo -attributes {a {b 1}} +# Object parameter specified via attribute methods +# (allow method modifieres and scripted configuration) -# Create instance of the class Foo -Foo create f1 -a 0 - -# Object f1 has a == 0 and b == 1 ----------------- -[source,tcl] ----------------- Class create Foo { :attribute a :attribute {b 1} @@ -763,6 +786,9 @@ ---------------- |[source,tcl] ---------------- +# Object parameter with configured slot, defining an attribute +# specific type checker + Class Person -slots { Attribute create sex -type "sex" { my proc type=sex {name value} { @@ -777,6 +803,9 @@ ---------------- |[source,tcl] ---------------- +# Object parameter with scripted definition, defining an attribute +# specific type checker + Class create Person { :attribute sex { :type "sex" @@ -796,10 +825,16 @@ ---------------- |[source,tcl] ---------------- -# Predefined value constraints: object, class, alnum, alpha, -# ascii, boolean, control, digit, double, false, graph, -# integer, lower, print, punct, space, true, upper, -# wordchar, xdigit +# Predefined value constraints: +# object, class, alnum, alpha, ascii, boolean, control, +# digit, double, false, graph, integer, lower, print, +# punct, space, true, upper, wordchar, xdigit +# +# User defined value constraints are possible. +# All parameter value checkers can be turned on and off. +# +# Define a boolean attribute and an integer attribute with a +# default Class create Foo -attributes { a:boolean @@ -819,48 +854,157 @@ ---------------- |[source,tcl] ---------------- -# Required parameter +# Required parameter: +# Define a required attribute a and a required boolean +# attribute b + Class create Foo -attributes { - a:boolean,required - {b:integer 1} + a:required + b:boolean,required } ---------------- [source,tcl] ---------------- Class create Foo { - :attribute a:boolean,required - :attribute {b:integer 1} + :attribute a:required + :attribute b:boolean,required } ---------------- |[source,tcl] --------------- -# Multivalued parameter not available +# Multiplicity for parameter not available ----------------- |[source,tcl] ---------------- -# Required parameter +# Parameter with multiplicity + Class create Foo -attributes { - ... - ints:integer,multivalued - {objs:object,multivalued ""} + {ints:integer,0..n ""} ;# list of integers, with default + objs:object,1..n ;# non-empty list of objects + obj:object,0..1 ;# single object, maybe empty } ---------------- [source,tcl] ---------------- Class create Foo { - ... - :attribute ints:integer,multivalued - :attribute {objs:object,multivalued ""} + :attribute {ints:integer,0..n ""} + :attribute objs:object,1..n + :attribute obj:object,0..1 } ---------------- |====================== -## allowempty -=== Method Parameters +==== Method Parameters -todo +The method parameters specifications in XOTcl 1 were limited and +allowed only value constraints for non positional arguments. NX and +XOTcl 2 provide value constraints for all kind of method parameters. +While XOTcl 1 required non-positional arguments to be listed in front of +positional arguments, this limitation is lifted in XOTcl 2. +[options="header",cols="asciidoc,asciidoc",frame="none",valign="middle"] +|====================== +|XOTcl |Next Scripting Language + +|[source,tcl] +---------------- +# Define method foo with non-positional parameters +# (x, y and y) and positional parameter (a and b) + +Class C +C instproc foo {-x:integer -y:required -z a b} {....} +C create c1 + +# invoke method foo +c1 foo -x 1 -y a 2 3 +---------------- +|[source,tcl] +---------------- +# Define method foo with non-positional parameters +# (x, y and y) and positional parameter (a and b) + +Class create C { + :public method foo {-x:integer -y:required -z a b} {....} + :create c1 +} +# invoke method foo +c1 foo -x 1 -y a 2 3 +---------------- + +|[source,tcl] +---------------- +# n.a. +---------------- +|[source,tcl] +---------------- +# Define various forms of parameters not available in XOTcl 1 + +Class create C { + # trailing (or interleaved) non-positional parameters + :public method m1 {a b -x:integer -y} {....} + + # postional parameters with value constraints + :public method m2 {a:integer b:boolean} {....} + + # optional postional parameter (trailing) + :public method set {varName value:optional} {....} + + # parameter with multiplicty + :public method m3 {-objs:object,1..n c:class,0..1} {....} + + # In general, the same list of value constraints as for + # object parameter is available (see above). + # + # User defined value constraints are possible. + # All parameter value checkers can be turned on and off. +} +---------------- +|====================== + +==== Return Value Checkers + +Return value checker are a functionality that was not yet available in +XOTcl 1. A return value checker assures that a method returns always a +parameter of a certain value. Return value checkers can be defined on +all forms of methods. Like for other value checkers, return +value checkers can be turned on and off. + +[options="header",cols="asciidoc,asciidoc",frame="none",valign="middle"] +|====================== +|XOTcl |Next Scripting Language + +|[source,tcl] +---------------- +# n.a. +---------------- +|[source,tcl] +---------------- +# Define method foo with non-positional parameters +# (x, y and y) and positional parameter (a and b) + +Class create C { + # Define method foo which returns an integer value + :method foo -returns integer {-x:integer} {....} + + # Define an alias for the Tcl command ::incr + # and assure, it always returns in integer + :alias incr -returns integer ::incr + + # Define a forwarder that has to return integer + :forward ++ -returns integer ::expr 1 + + + # Define a method that has to return a non-empty + # list of objects + :public class-object method instances {} -returns object,1..n { + return [:info instances] + } +} +---------------- +|====================== + + + === Interceptors ==== Register Mixin Classes and Mixin Guards