I have a class I use to manage collections of aggregated objects. I'm trying to use it with the -Class parameter option and instforwarding so that I can do things like this:
Test x x apples add Z x apples items
*That* part I can get to work as expected. But I can't get the default option of instforwarding to work for this case:
x apples
Some (simplified) sample code follows.
================================
package require XOTcl 1.3
namespace import ::xotcl::*
# Collection
Class Collection
Collection instproc new {className args} { eval $className [self]::[[self] autoname -instance $className] $args }
Collection instproc add {args} { foreach objName $args { $objName move [self]::[[self] autoname -instance [namespace tail [$objName info class]]] } }
Collection instproc items {} { return [[self] info children] }
Collection instproc remove {objName} { [self]::$objName destroy }
# CollectionParameter
::xotcl::Class::Parameter CollectionParameter -superclass Collection
# Test
Class Test -parameter { {_apples_ -Class CollectionParameter -default 1} {_oranges_ -Class CollectionParameter -default 1} }
# TestItem
Class TestItem
# Examples
Test instforward apples {%my _apples_} Test instforward oranges {%my _oranges_}
Test x x apples new TestItem x apples new TestItem
# this works puts [x apples items]
Test instforward apples -default {items add} {%my _apples_} Test instforward oranges -default {items add} {%my _oranges_}
Test z z apples new TestItem z apples new TestItem
# this works puts [z apples items]
# this doesn't puts [z apples]
On Monday 20 September 2004 17:33, MichaelL@frogware.com wrote:
I have a class I use to manage collections of aggregated objects. I'm trying to use it with the -Class parameter option and instforwarding so that I can do things like this:
Test x x apples add Z x apples items
*That* part I can get to work as expected. But I can't get the default option of instforwarding to work for this case:
x apples
Michael,
the default values are only used in te substitution of %1, which refers to the first argument of the invocation. The default ist used, whenever the argument is not specified in the invocation. So, essentially, the %1 was missing in your example (see below)
best regards -gustaf
=================================
Test instforward apples -default {items add} {%my _apples_} %1 Test instforward oranges -default {items add} {%my _oranges_} %1
Test z z apples new TestItem z apples new TestItem
# no arguments, use default puts [z apples]
Class GoldenDelicious GoldenDelicious apple1 GoldenDelicious apple2
# explicit add z apples add apple1
# implcit add (via default) z apples apple2
puts [z apples] =================================