Index: Makefile.in =================================================================== diff -u -r922c0ab9c756265f0793bda2cc69d50742c5bf88 -r92c1ac38cd3d93c59f2924a1d0eb79caa47f60b3 --- Makefile.in (.../Makefile.in) (revision 922c0ab9c756265f0793bda2cc69d50742c5bf88) +++ Makefile.in (.../Makefile.in) (revision 92c1ac38cd3d93c59f2924a1d0eb79caa47f60b3) @@ -261,7 +261,8 @@ $(src_doc_dir)/example-scripts/rosetta-tree.html \ $(src_doc_dir)/example-scripts/rosetta-multiple-distinct.html \ $(src_doc_dir)/example-scripts/rosetta-add-variable.html \ - $(src_doc_dir)/example-scripts/rosetta-clone.html + $(src_doc_dir)/example-scripts/rosetta-clone.html \ + $(src_doc_dir)/example-scripts/rosetta-multiple-inheritance.html %.html : %.tcl $(TCLSH) $(src_app_dir_native)/utils/source-doc-beautifier.tcl $< @@ -596,6 +597,7 @@ $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-multiple-distinct.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-add-variable.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-clone.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) + $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-multiple-inheritance.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) test-xotcl: $(TCLSH_PROG) $(TCLSH) $(xotcl_src_test_dir)/testo.xotcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) Index: TODO =================================================================== diff -u -r922c0ab9c756265f0793bda2cc69d50742c5bf88 -r92c1ac38cd3d93c59f2924a1d0eb79caa47f60b3 --- TODO (.../TODO) (revision 922c0ab9c756265f0793bda2cc69d50742c5bf88) +++ TODO (.../TODO) (revision 92c1ac38cd3d93c59f2924a1d0eb79caa47f60b3) @@ -5857,6 +5857,8 @@ - Added Rosetta example: https://rosettacode.org/wiki/Polymorphic_copy#Tcl +- Added Rosetta example: https://rosettacode.org/wiki/Inheritance/Multiple#Tcl + ======================================================================== TODO: @@ -5879,7 +5881,6 @@ (for the sake of completeness) https://rosettacode.org/wiki/Inheritance/Single - https://rosettacode.org/wiki/Inheritance/Multiple#Tcl (more substantial) https://rosettacode.org/wiki/Active_object Index: doc/example-scripts/rosetta-multiple-inheritance.html =================================================================== diff -u --- doc/example-scripts/rosetta-multiple-inheritance.html (revision 0) +++ doc/example-scripts/rosetta-multiple-inheritance.html (revision 92c1ac38cd3d93c59f2924a1d0eb79caa47f60b3) @@ -0,0 +1,830 @@ + + + + + +Listing of doc/example-scripts/rosetta-multiple-inheritance.tcl + + + + + +
+
+

Rosetta example: Inheritance/Multiple

+
+

Write two classes (or interfaces) Camera and MobilePhone, then write +a class CameraPhone which is both a Camera and a MobilePhone.

+ +
+
+
package req nx
+

NX offers class-based and mixin-based multiple inheritance. The +search order of features (methods, properties) along the class +hierarchy is computed using a scheme equivalent with L3 +linearization.

+

a) Class-based multiple inheritance

+
+
+
nx::Class create Camera
+nx::Class create MobilePhone
+
+nx::Class create CameraPhone -superclasses {Camera MobilePhone}
+

Show the resulting class search order:

+
+
+
% CameraPhone info superclasses -closure
+::Camera ::MobilePhone ::nx::Object
+% [CameraPhone new] info precedence
+::CameraPhone ::Camera ::MobilePhone ::nx::Object
+

b) Mixin-based multiple inheritance

+
+
+
nx::Class create CameraPhone -mixins {Camera MobilePhone}
+% CameraPhone info mixins
+::Camera ::MobilePhone
+

Show the resulting class search order:

+
+
+
% [CameraPhone new] info precedence
+::Camera ::MobilePhone ::CameraPhone ::nx::Object
+
+
+
+

+ + + Index: doc/example-scripts/rosetta-multiple-inheritance.tcl =================================================================== diff -u --- doc/example-scripts/rosetta-multiple-inheritance.tcl (revision 0) +++ doc/example-scripts/rosetta-multiple-inheritance.tcl (revision 92c1ac38cd3d93c59f2924a1d0eb79caa47f60b3) @@ -0,0 +1,38 @@ +# +# == Rosetta example: Inheritance/Multiple +# +# Write two classes (or interfaces) Camera and MobilePhone, then write +# a class CameraPhone which is both a Camera and a MobilePhone. +# +# https://rosettacode.org/wiki/Inheritance/Multiple +# + +package req nx +package req nx::test + +# +# NX offers class-based and mixin-based multiple inheritance. The +# search order of features (methods, properties) along the class +# hierarchy is computed using a scheme equivalent with L3 +# linearization. +# + +# +# a) Class-based multiple inheritance +# +nx::Class create Camera +nx::Class create MobilePhone + +nx::Class create CameraPhone -superclasses {Camera MobilePhone} + +# Show the resulting class search order: +? {CameraPhone info superclasses -closure} {::Camera ::MobilePhone ::nx::Object} +? {[CameraPhone new] info precedence} {::CameraPhone ::Camera ::MobilePhone ::nx::Object} + +# b) Mixin-based multiple inheritance + +nx::Class create CameraPhone -mixins {Camera MobilePhone} +? {CameraPhone info mixins} {::Camera ::MobilePhone} + +# Show the resulting class search order: +? {[CameraPhone new] info precedence} {::Camera ::MobilePhone ::CameraPhone ::nx::Object}