There are two actions involved with course selection. The first is simply creating a menu list of available selections, and the second is providing the required framework to support the selection. If TclTutor simply evaluated the examples, providing limited feedback to the student, then the different language processors could be handled with a state variable that defined the processor to call. However, TclTutor is designed to evaluate example code, and report any errors by highlighting the line with the error.
Every language processor has a different format for reporting syntactical errors, thus each language requires special parsing code. In TclTutor these error parsing procs return their output in a language neutral form (actually, for all the wrong reasons, they return error information formatted to resemble error output produced by Tk 4.0).
Each course of lessons has a file (named
language.cfg
), which contains the language specific
error parsing proc and sets various state variables that control the
execution of that language processor, such as the name of the processor
(Perl, Wish
), the full path, command line arguments, and strings which
must be added to the example code to make an executable program.
These configuration files provide the solution to the course selection
menu generation problem. TclTutor simply extracts the
file names ending in .cfg
from the directory using
glob
,
and a loop iterates through that list to create menu list entries.
In order to reduce problems
with having redundant code in multiple .cfg files,
state variables that can be modified in the base TclTutor code
are done in the proc NewCourse
when a course is selected, rather than being performed when
the
language.cfg file is sourced
.
The course selection menu list is created with this code:
set courseList [glob "$tutorGlobals(lessonDir)/*.cfg"]
;# iterate through the list, adding items to the courseMenu.
foreach fileName $courseList {
set name [file rootname [file tail $fileName]]
;# Set the currentlesson to 0 if it's not already set.
if {![info exists tutorGlobals($name.currentLesson)]} {
set tutorGlobals($name.currentLesson) 0;
}
$courseMenu add command -label $name -command "NewCourse $name $lessonMenu"
}
TclTutor allows the student to switch from course to course and always
return to the last lesson viewed. This is implemented by saving the
current lesson in the global state variables. The convention of saving
the current lesson in each course as tutorGlobals(
CourseName. currentLesson)
allows new lessons to be added without any modification to the code which
maintains this state.
When a new course is added, the initial lesson for
that course is set to 0. If the course had been available previously, the
value for tutorGlobals(
CourseName. currentLesson) would have been set when
the previous state was restored.