proc every {milliseconds body} {
eval $body
after $milliseconds [list every $milliseconds $body]
}
every 60000 {puts "Another minute just passed."}The classical language where code is data is LISP, since (in Tclish terms) any LISP command is also the list of the words of that command, and can be accessed as the elements of any other list. Tcl is formally just as powerful since everything is a string, but it is usually not practical to have Tcl code take Tcl scripts apart and modified, since there are few facilities available out of the box for handling Tcl scripts at a higher level than as a string of characters (there are packages for higher level handling, however). What is straightforward to do is:- storing code anywhere data can be stored,
- manufacturing code from arbitrary data (list-quoting), and
- combining pieces of code into larger pieces of code.
NEM Code is, of course, data as far as the interpreter or compiler is concerned. Most mainstream programming languages are sufficiently expressive to allow you to write a compiler or interpreter in them, so they all have the potential to treat code as data. Numerous ways of representing code exist, such as ASTs, S-expressions, strings, etc. The interesting questions then are:
- Can the language represent its own code as data? (Almost certainly possible)
- Does the language provide some sort of built-in datatype/operations to construct/manipulate code of the same language? (Usually not)
- Does the language provide a means of instantiating such constructed code as a process (i.e., running it: eval, compiling it, macros etc)? (Usually not)
- Does the language provide a means of causally interacting with the current process (i.e., [reflection], introspection, etc)? (Usually not)
- Does the language provide a means of executing the constructed code within the current process? (Usually not)
See also edit
Tools for transforming Tcl code
Tools for parsing Tcl code
Code in other languages than Tcl is data too
Other
- code is data is code, which realises the LISP ideal of having arbitrary programs being nested lists (and possible to manipulate as such), at the price of transforming them to something straightforwardly evaluatable by Tcl but not quite suited for human eyes.

