Meta-programming is the writing of code that writes itself. Tcl has lots of support for meta-programming: * It is very dynamic: commands can be created or modified during the execution of a script. * It treats both code and data as strings: new code can be generated on the fly. * It supports introspection so that a program can examine itself and make decisions based upon its current configuration. Meta-programming is not widely accepted as a programming technique, probably because it allows self-modifying code, which is a ''bad thing''. How can we take advantage of meta-programming to improve the performance and structure of Tcl (or other) code? ---- '''Advantages of Meta Programming''' * '''Performance''': Meta-programs represent data to be processed in terms of the low level data structures used by the script interpreter to represent the scripting language itself. Therefore, instead of being processed by an interpreted script manipulating script-level data structures, the data is processed by the compiled code of the language interpreter manipulating low level data structures directly. This removes the levels of indirection that slow down the execution of scripts, and so results in significant performance improvements. ---- '''Links about Meta Programming in Tcl''' * Bootstrap Script pattern [http://www-dse.doc.ic.ac.uk/~np2/patterns/scripting/bootstrap.html] * Active File pattern [http://www-dse.doc.ic.ac.uk/~np2/patterns/scripting/data-as-code.html] * Command Interceptor pattern [http://www-dse.doc.ic.ac.uk/~np2/patterns/scripting/interceptor.html] ----