Self-modifying code is an unusual feature in programming languages, and not one I've seen so beautifully used anywhere else than in Tcl. There are several examples of self modifying procedures on this wiki: * [Let unknown know] re-writes [unknown] * [braintwisters] has several examples * [RS]'s [every] which "replaces itself" * .. there are plenty more Procedures that modify themselves in Tcl generally follow a pattern like this: ====== proc hibye {} { puts "Hello, world!" proc hibye {} { puts "Goodbye, world" rename repeat {} } } ====== % hibye Hello, world! % hibye Goodbye, world % hibye invalid command name "hibye" It is easy to end up in [Quoting hell] when rewriting procedures. A pattern that seems to have become common is using [string map] in this fashion: ====== proc and_then {more} { puts "No more and then!" proc and_then {more} [string map [list @BODY@ [info body and_then]] " $more @BODY@ "] } ====== % and_then {puts ".. and then"} No more and then! % and_then {puts ".. and then"} .. and then No more and then! % and_then {puts ".. and then"} .. and then .. and then No more and then!