Home > Archive > Tcl > April 2007 > Newby question about colons
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Newby question about colons
|
|
| pn8830 2007-04-25, 7:07 pm |
| Hi,
It's probably a very simple question but I could not find answer
mostly because google does nto accept :: as a search pattern :(
Why do some Tcl commands have :: in them (for example md5 hash -
[::md5::md5] ). This must be some sort of naming convention and this
should be for a reason. I would like to know that reason just to
understand things better. Could someone help?
Thanks,
PN.
| |
| Bryan Oakley 2007-04-25, 7:07 pm |
| pn8830 wrote:
> Hi,
>
> It's probably a very simple question but I could not find answer
> mostly because google does nto accept :: as a search pattern :(
> Why do some Tcl commands have :: in them (for example md5 hash -
> [::md5::md5] ). This must be some sort of naming convention and this
> should be for a reason. I would like to know that reason just to
> understand things better. Could someone help?
>
> Thanks,
> PN.
>
:: is a namespace separator. :: by itself refers to the global
namespace. So, if you see ::foo, it means to explicitly run the command
"foo" defined in the global namespace.
This is mostly used if you redefine a core command in a namespace and
want to reference the core command instead of the namespace command. For
example:
namespace eval Foo {
proc set {a b} {
puts "this is set, inside of foo"
}
proc bar {} {
# use the "set" defined in this namespace
set a b
# use the core "set" command
::set a b
}
}
::Foo::bar
More information on namespaces is here:
http://www.tcl.tk/man/tcl8.4/TclCmd/namespace.htm#M20
--
Bryan Oakley
http://www.tclscripting.com
|
|
|
|
|