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

Re: [Xotcl] Error or normal behavior?

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Wed, 08 Dec 2010 06:39:01 +0100

On 08.12.10 05:40, Victor Mayevski wrote:
> It came to my attention that [namespace import -force nx::*] is a
> requirement and not an option, otherwise things don't work right.
> Example:
>
> nx::Class create C
> C method init args {puts [self]; next}
> C create c
> #error, commands "self" and "next" do not exist, but if I first do
> [namespace import -force nx::*], everything works fine.
well, if i take the first sentence literally, this is not true.
there are several options:

if one uses a plain tcl shell, one can use

a)
      package req nx

      nx::Class create C
      C method init args {puts [nx::self]; nx::next}
      C create c

b)
      package req nx
      namespace path nx

      nx::Class create C
      C method init args {puts [self]; next}
      C create c

c)
      package req nx
      namespace import nx::*

      nx::Class create C
      C method init args {puts [self]; next}
      C create c

Concerning (c): there is no need to use "-force", except
these commands were already imported (e.g. from some
other package).

One can use alternatively the "nxsh" (tcl-file, which does a
      package req nx
      namespace import nx::*
automatically) and then in the script file just

      nx::Class create C
      C method init args {puts [self]; next}
      C create c
> This is not how I thought the namespaced commands should work. Is this
> a feature or a bug? If not a bug, then it needs to be clearly
> documented.
I don't understand, what you expected. If you use just (a)
then Tcl has no indication, what "self" or "next" should be
used.
For unprefixed names, Tcl requires to have to use either
"namespace import" or "namespace path".

The behavior is the same as in XOTcl 1. XOTcl/nx do not play
any magic games with namespaces, they just use the standard
tcl behaviour.

-gustaf neumann