Nitesh
Nitesh

Reputation: 157

Why namespace with empty braces is used in packages

I am having a package TEX.

package require ABC
package provide TEX 1.0

namespace eval ::65FGA {

}

proc ::65FGA::runSuite {{setupFile ""} args} {
Proc body
proc body
}

I am not getting why namespace with empty braces is used..

Upvotes: 2

Views: 125

Answers (2)

kostix
kostix

Reputation: 55483

Do you mean that

namespace eval ::65FGA {

}

bit?

This command just creates a namespace "65FGA" and then evaluates an empty string (empty script if this sounds more sensible to you). As a result, the said namespace is created but it does not yet contain anything in it.

In this code, you could remove the command invocation being discussed and it won't affect anything. Hence most probably it serves narrative purpose stating clear that the package is creating the said namespace (which it then populates with at leat one procedure).

UPDATE: Struck through the false statement (thanks to Eric Melski). The namespace must exist, indeed, before an attempt is made to create anything in it (via proc or set commands).

Upvotes: 3

glenn jackman
glenn jackman

Reputation: 246877

It may just be a matter of style:

namespace eval ::my_namespace {}
proc ::my_namespace::procname {} {...}

versus

namespace eval ::my_namespace {
    proc procname {} {...}
}

Upvotes: 5

Related Questions