Index: TODO =================================================================== diff -u -r240cd3e5e7bfd197336735684cbac012ad84563b -rac2bbda827dff056beb23cf8400ab77b6996d1e8 --- TODO (.../TODO) (revision 240cd3e5e7bfd197336735684cbac012ad84563b) +++ TODO (.../TODO) (revision ac2bbda827dff056beb23cf8400ab77b6996d1e8) @@ -4506,11 +4506,16 @@ - use "typeName" to shorten reported names of parameters - use camel case for reported names +Traits: +- changed from traits-as-objects to traits-as-classes. This + allows for higher orthogonality of traits and class definitons + and allows in principle traits for object-specific methods + (not fully implemented/tested) +- fixed property/variable inheritance in traits. + ======================================================================== TODO: -- fix property inheritance in traits (nx-traits.tcl) - - reconsider #? {c1 cget -mixin} "" ? {c1 cget -object-mixin} "" @@ -4812,21 +4817,6 @@ - constants in type converter (in and out) -- genau genommen sind folgende info-Methoden unnötig: - - obj info mixin - - obj info filter - - obj info class - * obj info is - - cl info mixin - - cl info filter - - cl info superclass -# SS: Sie spielen vermutlich auf die Redundanz der getter seite der - relation slots an. Mmmh. Die info-Sicht bietet in einigen der Fälle - ?pattern? an, das wäre als Unterschied zu nennen (das ließe sich - aber auch in die relation slots integrieren, etwa [obj mixin search - ]. Zudem ist es ein Fallback, wenn mixin|filter|class - überladen wären (ein sicherer hafen), aber ob das als argument - genügt, die info-varianten zu behalten?! #if 1 /* TODO: the following check operations is xotcl1 legacy and is not @@ -4843,6 +4833,8 @@ For future releases (after first alpha/beta release) + + * extend traits (object-specific traits, test cases, etc.) - Stefan: Still valid, IMHO: todo: don't hard-code registering command name "method" / NSF_METHOD"; parts of the introspection Index: doc/example-scripts/traits-composite.tcl =================================================================== diff -u -r2872e1f0a6523c7fb44952492e05414c4f8d9c84 -rac2bbda827dff056beb23cf8400ab77b6996d1e8 --- doc/example-scripts/traits-composite.tcl (.../traits-composite.tcl) (revision 2872e1f0a6523c7fb44952492e05414c4f8d9c84) +++ doc/example-scripts/traits-composite.tcl (.../traits-composite.tcl) (revision ac2bbda827dff056beb23cf8400ab77b6996d1e8) @@ -19,13 +19,13 @@ # # Define the methods provided by this trait: # - :public object method atStart {} {expr {[:position] == [:minPosition]}} - :public object method atEnd {} {expr {[:position] == [:maxPosition]}} - :public object method setToStart {} {set :position [:minPosition]} - :public object method setToEnd {} {set :position [:maxPosition]} - :public object method maxPosition {} {llength ${:collection}} - :public object method minPosition {} {return 0} - :public object method nextPosition {} {incr :position 1} + :public method atStart {} {expr {[:position] == [:minPosition]}} + :public method atEnd {} {expr {[:position] == [:maxPosition]}} + :public method setToStart {} {set :position [:minPosition]} + :public method setToEnd {} {set :position [:maxPosition]} + :public method maxPosition {} {llength ${:collection}} + :public method minPosition {} {return 0} + :public method nextPosition {} {incr :position 1} # The trait requires a method "position" and a variable "collection" # from the base class or other traits. The definition is incomplete @@ -43,8 +43,8 @@ # # Methods provided by this trait: # - :public object method on {collection} {set :collection $collection; :setToStart} - :public object method next {} { + :public method on {collection} {set :collection $collection; :setToStart} + :public method next {} { if {[:atEnd]} {return ""} else { set r [lindex ${:collection} ${:position}] :nextPosition @@ -67,8 +67,8 @@ # # Methods provided by this trait: # - :public object method on {collection} {set :collection $collection; :setToEnd} - :public object method nextPut {element} { + :public method on {collection} {set :collection $collection; :setToEnd} + :public method nextPut {element} { lappend :collection $element :nextPosition return "" @@ -97,3 +97,4 @@ ? {r1 atEnd} 0 ? {r1 next} a ? {r1 next} b + Index: doc/example-scripts/traits-simple.tcl =================================================================== diff -u -r2872e1f0a6523c7fb44952492e05414c4f8d9c84 -rac2bbda827dff056beb23cf8400ab77b6996d1e8 --- doc/example-scripts/traits-simple.tcl (.../traits-simple.tcl) (revision 2872e1f0a6523c7fb44952492e05414c4f8d9c84) +++ doc/example-scripts/traits-simple.tcl (.../traits-simple.tcl) (revision ac2bbda827dff056beb23cf8400ab77b6996d1e8) @@ -20,21 +20,21 @@ # # Define the methods provided by this trait: # - :public object method atStart {} {expr {[:position] == [:minPosition]}} - :public object method atEnd {} {expr {[:position] == [:maxPosition]}} - :public object method setToStart {} {set :position [:minPosition]} - :public object method setToEnd {} {set :position [:maxPosition]} - :public object method maxPosition {} {llength ${:collection}} - :public object method on {collection} {set :collection $collection; :setToStart} - :public object method next {} { + :public method atStart {} {expr {[:position] == [:minPosition]}} + :public method atEnd {} {expr {[:position] == [:maxPosition]}} + :public method setToStart {} {set :position [:minPosition]} + :public method setToEnd {} {set :position [:maxPosition]} + :public method maxPosition {} {llength ${:collection}} + :public method on {collection} {set :collection $collection; :setToStart} + :public method next {} { if {[:atEnd]} {return ""} else { set r [lindex ${:collection} ${:position}] :nextPosition return $r } } - :public object method minPosition {} {return 0} - :public object method nextPosition {} {incr :position 1} + :public method minPosition {} {return 0} + :public method nextPosition {} {incr :position 1} # This trait requires a method "position" and a variable # "collection" from the base class. The definition is incomplete in Index: generic/predefined.h =================================================================== diff -u -rbca161db07ae2fe223f49b5aa5e44e7149cf9e67 -rac2bbda827dff056beb23cf8400ab77b6996d1e8 --- generic/predefined.h (.../predefined.h) (revision bca161db07ae2fe223f49b5aa5e44e7149cf9e67) +++ generic/predefined.h (.../predefined.h) (revision ac2bbda827dff056beb23cf8400ab77b6996d1e8) @@ -87,7 +87,6 @@ "return $result}\n" "set ::nsf::parameter::syntax(::nsf::xotclnext) \"?--noArgs? ?/arg .../?\"\n" "set ::nsf::parameter::syntax(::nsf::__unset_unknown_args) \"\"\n" -"set ::nsf::parameter::syntax(::nsf::exithandler) \"?get?|?set /cmds/?|?unset?\"\n" -"puts stderr \"::nsf children [namespace children ::nsf]\"}\n" +"set ::nsf::parameter::syntax(::nsf::exithandler) \"?get?|?set /cmds/?|?unset?\"}\n" ""; Index: library/lib/nx-traits.tcl =================================================================== diff -u -r31404a50d429bd67e904a70797c4f67674fab09f -rac2bbda827dff056beb23cf8400ab77b6996d1e8 --- library/lib/nx-traits.tcl (.../nx-traits.tcl) (revision 31404a50d429bd67e904a70797c4f67674fab09f) +++ library/lib/nx-traits.tcl (.../nx-traits.tcl) (revision ac2bbda827dff056beb23cf8400ab77b6996d1e8) @@ -67,20 +67,24 @@ # nsf::proc nx::trait::add {obj -per-object:switch traitName {nameMap ""}} { array set map $nameMap - foreach m [$traitName info object methods -callprotection all] { + foreach m [$traitName info methods -callprotection all] { if {[info exists map($m)]} {set newName $map($m)} else {set newName $m} # do not add entries with $newName empty if {$newName eq ""} continue - set traitMethodHandle [$traitName info object method definitionhandle $m] + set traitMethodHandle [$traitName info method definitionhandle $m] if {${per-object} || ![::nsf::is class $obj]} { - $obj object alias $newName $traitMethodHandle + $obj public object alias $newName $traitMethodHandle + foreach slot [$traitName info object variables] { + #puts "$obj - wanna define: [$traitName info variable definition $slot]" + $obj {*}[lrange [$traitName info variable definition $slot] 1 end] + } } else { $obj public alias $newName $traitMethodHandle # We define property inheritance for the time being only for # instance properties. - foreach slot [$traitName info object slots] { - puts "$obj - wanna define property [$slot info slot definition]" - #$obj property $d + foreach slot [$traitName info variables] { + #puts "$obj - wanna define: [$traitName info variable definition $slot]" + $obj {*}[lrange [$traitName info variable definition $slot] 1 end] } } } @@ -123,36 +127,31 @@ nx::trait::add [self] $traitName $nameMap } -nx::Class public method "require class trait" {traitName {nameMap ""}} { - # adding a trait to the class object - nx::trait::require $traitName - nx::trait::checkObject [self] $traitName - nx::trait::add [self] -per-object $traitName $nameMap -} +#nx::Object public method "require object trait" {traitName {nameMap ""}} { +# puts "[self] require object trait $traitName -- MAYBE OBSOLETE" +# # adding a trait to an object +# nx::trait::require $traitName +# nx::trait::checkObject [self] $traitName +# nx::trait::add [self] -per-object $traitName $nameMap +#} -nx::Object public method "require trait" {traitName {nameMap ""}} { - # adding a trait to an object - nx::trait::require $traitName - nx::trait::checkObject [self] $traitName - nx::trait::add [self] -per-object $traitName $nameMap -} - # # The class "nx::Trait" provides the basic properties and methods needed for # the trait management. # -nx::Class create nx::Trait { +nx::Class create nx::Trait -superclass nx::Class { :property {package} :property -incremental {requiredMethods:0..n ""} :property -incremental {requiredVariables:0..n ""} :public method "require trait" {traitName {nameMap ""}} { # adding a trait to a trait nx::trait::require $traitName - nx::trait::add [self] -per-object $traitName $nameMap + nx::trait::add [self] $traitName $nameMap set finalReqMethods {} + # remove the methods from the set of required methods, which became available foreach m [lsort -unique [concat ${:requiredMethods} [$traitName requiredMethods]]] { - if {[:info lookup method $m] eq ""} {lappend finalReqMethods $m} + if {[:info methods $m] eq ""} {lappend finalReqMethods $m} } #puts "final reqMethods of [self]: $finalReqMethods // defined=[:info methods]" set :requiredMethods $finalReqMethods