[http://www.equi4.com/pub/om/pub/tclerswiki.png] ** Intro ** A list of exercises for those learning [Tcl] ** Description ** In the process of [Beginning Tcl%|%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 [People & Community%|%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 the arguments ''minimum'', and ''maximum'', and returns a random integral `$number` such that $minimum <= $number <= $maximum '''random string''': Write a procedure that takes the argument ''length'', and returns a string of random lower and upper case letters of that length. '''random guesses''': Write a procedure that takes the 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"). '''7sum''': Write a procedure that takes any number of arguments, interprets each as a base-7 integer, and sums them. '''key principles:''' interpret strings in some arbitrary way. '''fullglob''': Write a procedure that that takes the arguments ''directory'' and ''pattern'', and returns a list of files, each whose name relative to ''directory'' matches the glob-style pattern, including any glob-style patterns in any directory component in ''pattern''. For example `[fullglob /name/of some/otherdir*/fname*]` might return `/name/of/some/otherdir1/fnameA /name/of/some/otherdir2/fnameA`. Write both a version that performs this task using a recursive strategy, and a version that does the same using an iterative strategy. '''fulltreeglob''': Write a procedure like '''fullglob''', except that it additionally searches the entire directory tree of each directory that matches the full directory components of ''pattern'' for files or directories whose basename matches the last component in ''pattern''. Write both a version that performs this task using a recursive strategy, and a version that does the same using an iterative strategy. '''timer''': Write a program that displays elapsed time to a terminal. Use an event-driven style. Enter the event loop at the end of the script with `[vwait] forever`. Use `[after]` to schedule elapsed time updates. Provide a mechanism to pause and resume. Estimated code length: 40 lines. '''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 '''fibonacci series''': 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. <> Education