Version 5 of namespace eval

Updated 2014-04-24 18:32:14 by pooryorick

namespace eval, evaluates a script in a given namespace.

See Also

namespace
eval

Synopsis

namespace eval namespace arg ?arg ...?

Description

args are concatenated together with a space between each one in the same fashion as eval, and the result is evaluated in the namespace called namespace. If the namespace does not already exist, it is created. If more than

If namespace has leading namespace qualifiers and any leading namespaces do not exist, they are automatically created.

Unlike eval, namespace eval creates a new level, and uplevel accesses the level that called namespace eval. In spite of this, return within namespace eval operates as if it were uplevel return, i.e., it causes the caller of namespace eval to return. It would probably be more useful if return within a namespace eval script behaved the way it does within source ... script.

For better performance, namespace eval ... is usually byte-compiled when it is given one argument which is a literal string:

proc main {
    namespace eval [info cmdcount] {
        set msg {this script is eligible to be byte-compiled}
        return $msg
    }
}