Intro
A list of exercises for those learning Tcl
Description
In the process of Learning Tcl, it can be helpful to have a set of references exercises that serves as an additional resource to other curricula. The following is a list of exercises that can be practiced in order to become a more proficient Tcl programmer.
After an exercise is complete, post your work somewhere and ask the community to try to break it. You can learn a lot this way!
Guidelines for Contributors
The exercises should be written so as to maximize their educational value. Each exercise should try to introduce at most one concept not yet introduced by previous exercises, with the minimal amount of specification necessary to illustrate the concept. It should be possible to write a solution that doesn't require much auxiliary code.
Exercises
- random number
- Write a procedure that takes two arguments, minimum, and maximum, and returns a random integral $number such that $minimum <= $number <= $maximum
- random string
- Write a procedure that takes one argument, length, and returns a string of random lower and upper case letters of that length.
- random guesses
- Write a procedure that takes one argument, integer, which is any integer, and randomly chooses numbers from 0 through that integer until it randomly chooses a number equal to integer, and returns the number of "guesses" it had to make.
- re-order
- Write a procedure that takes one argument, $word, which is a single English word, and re-orders the letters so that they are in alphabetical order ("A" before "a", and "a" before "B").
- dedent
- Write a procedure that takes one argument, $text and removes the common leading whitespace characters from all the lines of $text. When determining what is common whitespace, don't use the contents of lines containing only whitespace, and remove all whitespace from such lines
- the fibonacci series is a classic
- Write a procedure that generates a fibonacci number list of specified length. Extra credit: write a version that uses recursion, and one that doesn't.
Tk Exercises
This section may eventually have its own page, but is included here for the time being.
- file browser
- Write a file browser that includes two visual components: a label indicating the current directory and a listbox below the label showing the files in that directory. Use the [[pack] geometry manager.
- file browser2
- Add a window to the right of the directory indicator and file list that shows the contents of the file if it is text. Hint: the directory indicator and file list into a frame. Hint: pack the content window to the right side, and let the frame containing the directory indicator and file list continue to pack by default to the top.