Execute HQ9+/Tcl

From Rosetta Code
Revision as of 19:13, 22 July 2009 by rosettacode>Dkf (Added an implementation in Tcl; see page for why this is interesting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Execute HQ9+/Tcl is part of RCHQ9+. You may find other members of RCHQ9+ at Category:RCHQ9+.
Execute HQ9+/Tcl is an implementation of HQ9+. Other implementations of HQ9+.

This implementation has the feature that if you feed itself in as the program, it prints itself out. So the implementation of a language with a quine operation is a quine in the language implemented. This feels rather appropriate...
<lang tcl>set d [read [expr {$argc?[open [lindex $argv 0]]:"stdin"}]] for {set i [set a 0]} {$i<[string len $d]} {incr i} {

   switc\u0068 -- [string index [string tolower $d] $i] \u0068 {

puts "\u0048ello, world!"

   } q {puts -nonewline $d} [expr 10-1] {

for {set b [expr 100-1]} 1 {} { puts "$b bottle[expr {$b-1?{s}:{}}] of beer on t\u0068e wall" puts "$b bottle[expr {$b-1?{s}:{}}] of beer" incr b -1 puts "take one down and pass it around" puts "$b bottle[expr {$b-1?{s}:{}}] of beer on t\u0068e wall" if {$b} {puts ""} else break }

   } \x2b {incr a}

}</lang>