Index: Makefile.in =================================================================== diff -u -rf71f786b01f7ad3d6749bc43c14c5f5d39658480 -r21a0283e3b67fb56e9dc782b628db602e21c9ac7 --- Makefile.in (.../Makefile.in) (revision f71f786b01f7ad3d6749bc43c14c5f5d39658480) +++ Makefile.in (.../Makefile.in) (revision 21a0283e3b67fb56e9dc782b628db602e21c9ac7) @@ -234,6 +234,7 @@ $(src_doc_dir)/example-scripts/rosetta-polymorphism.html \ $(src_doc_dir)/example-scripts/rosetta-serialization.html \ $(src_doc_dir)/example-scripts/rosetta-singleton.html \ + $(src_doc_dir)/example-scripts/rosetta-unknown-method.html \ %.html : %.tcl $(TCLSH) $(src_app_dir_native)/utils/source-doc-beautifier.tcl $< @@ -445,7 +446,7 @@ $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-polymorphism.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-serialization.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-singleton.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) - $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-singleton.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) + $(TCLSH) $(src_doc_dir_native)/example-scripts/rosetta-unknown-method.tcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) test-xotcl: $(TCLSH_PROG) $(TCLSH) $(xotcl_src_test_dir)/testo.xotcl -libdir $(PLATFORM_DIR) $(TESTFLAGS) Index: TODO =================================================================== diff -u -rf71f786b01f7ad3d6749bc43c14c5f5d39658480 -r21a0283e3b67fb56e9dc782b628db602e21c9ac7 --- TODO (.../TODO) (revision f71f786b01f7ad3d6749bc43c14c5f5d39658480) +++ TODO (.../TODO) (revision 21a0283e3b67fb56e9dc782b628db602e21c9ac7) @@ -3307,9 +3307,14 @@ * all examples are tested via regression test * all examples are pretty-printed via asciidoc * added example rosetta-abstract-type.tcl + * added example rosetta-unknown-method.tcl TODO: + - example-scripts: + * add ./apps/utils/source-doc-beautifier.tcl to the repository + * fix the file-handle output/formatting in rosetta-serialization.tcl + - nx: * maybe provide a replacement for -attributes, but without the magic variable. Index: doc/example-scripts/rosetta-serialization.tcl =================================================================== diff -u -r5693145107c55b5f64bf0fb487aa43e0f2238f1a -r21a0283e3b67fb56e9dc782b628db602e21c9ac7 --- doc/example-scripts/rosetta-serialization.tcl (.../rosetta-serialization.tcl) (revision 5693145107c55b5f64bf0fb487aa43e0f2238f1a) +++ doc/example-scripts/rosetta-serialization.tcl (.../rosetta-serialization.tcl) (revision 21a0283e3b67fb56e9dc782b628db602e21c9ac7) @@ -32,7 +32,7 @@ # +i am Fido alive true+ # # Serialize the animals to a file -? {set f [open /tmp/dump w]} "file5" +set f [open /tmp/dump w] ? {foreach i [Animal info instances] { puts $f [$i serialize] }} "" ? {close $f} "" Index: doc/example-scripts/rosetta-unknown-method.tcl =================================================================== diff -u --- doc/example-scripts/rosetta-unknown-method.tcl (revision 0) +++ doc/example-scripts/rosetta-unknown-method.tcl (revision 21a0283e3b67fb56e9dc782b628db602e21c9ac7) @@ -0,0 +1,34 @@ +# +# == Rosetta Example: Respond to an unknown method call +# For details see http://rosettacode.org/wiki/Respond_to_an_unknown_method_call +# +package req nx +package req nx::test + +# +# Modelled after the Python version +# + +nx::Class create Example { + + :public method foo {} {return "This is foo"} + :public method bar {} {return "This is bar"} + + :method unknown {method args} { + set result "Tried to handle unknown method '$method'." + if {[llength $args] > 0} { + append result " It had arguments '$args'." + } + return $result + } +} + +# === Demonstrating the behavior in a shell: +# +# Create an instance of Example +? {set e [Example new]} "::nsf::__#0" + +? {$e foo} "This is foo" +? {$e bar} "This is bar" +? {$e grill} "Tried to handle unknown method 'grill'." +? {$e ding dong} "Tried to handle unknown method 'ding'. It had arguments 'dong'."