Quines are self-reproducing programs, at least that's how this page defines them: http://www.nyx.net/~gthompso/quine.htm ''Here are the Tcl entries, as swiped from the Tcl page on that site...'' ---- '''Joe Miller''' - this has the unfortunate side effect of putting itself in x. set x {set x {@}; regsub @ $x $x x; set x}; regsub @ $x $x x; set x ---- '''Frank Stajano''' (fstajano@orl.co.uk) - basically the same as above set l {set l {L};regsub L $l $l p;puts $p};regsub L $l $l p;puts $p ---- '''Joe Miller''' join [split a{a} a] {join [split a{a} a] } ---- '''Joe Miller''' join {{} \{ \}} {join {{} \{ \}} } ---- ''Not from the site, but perhaps as instructive:'' ''KBK'' (12 January 2001) -- Working through a quine can help understand how to write a procedure that generates Tcl code, and how to use the [[info]] command. Consider the following: proc Quine {} { append s { } [list proc Quine [info args Quine] [info body Quine]] \n append s { puts [Quine]} \n return $s } puts [Quine] Of course, since [[info args Quine]] is known to be empty, the following would also work: proc Quine {} { append s { } [list proc Quine {} [info body Quine]] \n { puts [Quine]} \n } puts [Quine] The technique is useful in writing Tcl procedures that generate Tcl code, for instance to make other procedures, compose widget bindings, or execute complicated [[uplevel]] constructs. ---- Here is a variant of the previous example that uses no hardcoded values, so Quine is self replicating, and then a "rename Quine A" will still work, i.e. A is self replicating. proc Quine {} { set procName [lindex [info level 0] 0] set argList [info args $procName] set body [info body $procName] puts "[list proc $procName $argList $body]\n$procName\n" } Quine or a more terse version proc Quine {} { foreach {p a} [info level 0] {set b [info body $p]} puts "[list proc $p $a $b]\n$p\n" } Quine -BBH ---- [RS] has the shortest Tcl quine: {} The empty string is a legal script, can be used as argument to [eval], and returns - an empty string, which is the complete source text. % expr {{}==[eval {}]} 1 QED. [FW]: Heh, yeah. Though technically you mean , not {} ;) The blank string has been noted several times as the fundamental multiple-language quine (for languages that don't require any code to do nothing, at least). Oh, and also, your test script isn't exactly right, because a quine is usually supposed to print something (or nothing), not return it, but the empty script does both correctly, so you're sort of right. ---- [category tutorial]