A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
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.
# 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.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.