Exercises

  1. Is Tcl like any other language you know? Bourne shell? C shell? Lisp? C?

  2. As best as you can remember (or guess), write down the precedence table for Tcl expressions. Now look it up in the reference material. How close were you? Repeat this exercise with Perl, C, Lisp, and APL.

  3. What is the best thing about Tcl? What is the worst thing about Tcl? (That bad, eh?)

  4. Try putting comments where they do not belong—for instance, inside the arguments to a procedure. What happens?

  5. Write a procedure to reverse a string. If you wrote an iterative solution, now write a recursive solution or vice versa.

  6. Repeat the previous exercise but with a list instead of a string.

  7. Write a procedure to rename all the files in a directory ending with .c to names ending in ".cc“.

  8. Write a procedure that takes a list of variable names and a list of values, and sets each variable in the list to the respective value in the other list. Think of different alternatives to handle the case when the lists are of different lengths.

  9. Write a procedure that creates a uniquely-named temporary file.

  10. Write a procedure that can define other procedures that automatically have access to global variables.

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.