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

Re: [Xotcl] why Attribute is not imported?

From: Stefan Sobernig <>
Date: Mon, 02 Nov 2009 09:29:10 +0100


> XOTcl 1.6.4, works ok from xotclsh and when 'namespace import ::xotcl::*'
> comes right after 'package require XOTcl' and not within test1 namespace.

This behaviour is due to an interaction between the implementation
strategy for slots as implemented in XOTcl 1.5+ and the standard
namespace/command resolution rules of Tcl.

(::xotcl::)Attribute is declared and resolved for the scope of a
per-object namespace ::test1::Test::slot. This namespace is acquired
upon calls to the slot method of ::xotcl::Class. You may find out by
inspecting the return value of [namespace current] (see below). While
this is merely an implementation detail and should not concern the XOTcl
developer, it interferes with the way Tcl resolves relatively-qualified
command (and variable) names. While slightly more complex at second
sight, generally speaking, the command name (e.g., Attribute) is first
searched for in the current ns (::test1::Test::slot) and then in the
global one (::):

see Section "NAME RESOLUTION" at

Intermittent ones are skipped (e.g., ::test1, ::test1::Test). Hence the
behaviour you are observing. This also explains why a [namespace import
::xotcl::*] in the /global/ ns (e.g., following [package req XOTcl]) is
a valid fix.

You may also consider:

1. fully-qualified command names: ::xotcl::Attribute
2. a preceding [namespace import ::xotcl::*] in the '-slots' block (see
3. use of [namespace path] starting with 8.5 (see below)


package provide test1 0.1
package require XOTcl

# ::test1
namespace eval ::test1 {
   # [namespace current] -> ::test1
   namespace import ::xotcl::*
   # alternatively: namespace path ::xotcl
   Class ::test1::Test -slots {
     # [namespace current] -> ::test1::Test::slot
     namespace import ::xotcl::*
     # alternatively: namespace path ::xotcl
     Attribute name
   namespace export Test
namespace import ::test1::*