Fizz Buzz in Tcl

Published on 09 October 2025 (Updated: 09 October 2025)

Welcome to the Fizz Buzz in Tcl page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

# This approach is exclusively to show the capabilities and flexibility of Tcl.
# It doesn't deserve being this overengineered in the normal case. :P

proc fizzbuzz {rules {limit 100}} {
	namespace eval ::fizzbuzz {
		namespace export *
		namespace ensemble create
	}

	foreach {div word} $rules {
		proc ::fizzbuzz::$word {n} [format {
			expr {($n %% %d) == 0 ? "%s" : ""}
		} $div $word]
	}

	for {set n 1} {$n <= $limit} {incr n} {
		set s ""
		foreach {div word} $rules {
			append s [::fizzbuzz::$word $n]
		}
		puts [expr {$s eq "" ? $n : $s}]
	}
}

fizzbuzz {3 Fizz 5 Buzz}

Fizz Buzz in Tcl was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.