Version 0 of Problems and Solutions

Updated 2006-12-29 20:50:26

On this page I will write about little problems which I have with Tcl and about how I solve those problems. I think that these problems are so small, they don't deserve a whole wiki page, but are worth mentioning anyway.

Anybody is welcome to add their problems and solutions, since this is after all a wiki.

-JMBP


When looking at most modules you see, code like this is everywhere:

  proc ::base64::encode { ... } { ...
  ...
  proc ::base64::decode { ... } { ...
  ...

Lots of typing to simply put a few procs into a seperate namespace. It may seem that this is a trivial issue - and it is. But I think it is worth looking for an alternative. So, I simply thought this one up:

  proc _proc { name args body } {
    proc "::${::_namespace}::$name" args body
  }

To use:

  set _namespace "base64"
  ...
  _proc encode { ... } { ...
  ...
  _proc decode { ... } { ...
  ...

I have not simply temporarily replaced proc because that could mess up when other modules are loaded.

Would be happy to hear about improvements to this.