View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] Problem With Forwarding Defaults

From: <MichaelL_at_frogware.com>
Date: Mon, 20 Sep 2004 11:33:19 -0400

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]