Guided programming and automated error analysis in an intelligent Prolog tutor

https://doi.org/10.1016/j.ijhcs.2004.02.001Get rights and content

Abstract

We present a Prolog programming technique-based approach to guided programming and automated error analysis in Prolog tutoring. The concept of Prolog programming technique is used to characterize and classify programs. Each class of programs use the same programming technique and share the common pattern of code. A set of programming technique grammar rules are defined for each class of programs. These rules are used for programming technique recognition, program construction, and program parsing. A programming technique frame is used to represent the programming technique-related knowledge for each class of programs. A program frame is used to represent the coding-related knowledge for the reference program of each of the most specialized programming techniques. The representation of the programming technique grammar rules, programming technique-related knowledge, and coding-related knowledge provides the basis for guided programming and automated error analysis in tutoring. Our approach to error analysis however does not rely on the representation of buggy versions of the program. Automated error analysis in our approach is done on the basis of comparing the parsings of both the student program and the reference program. Our approach has been implemented in a Prolog tutoring system called the Prolog Tutor, which has been tested on a collection of 125 programs for list reversal. The Prolog Tutor performs well on these tests in terms of programming technique recognition, error detection, and error correction.

Introduction

Prolog has a simple syntax and few program constructs. So the language knowledge itself does not present any serious problems to Prolog novices. It appears fairly easy for them to start programming in Prolog. Studies have, however, shown that they often have many difficulties with Prolog programming due to their lack of structured programming knowledge (Taylor and du Boulay, 1987; Taylor, 1999; van Someren, 1990). For instance, they might not be quite sure what pattern of code should be used. This type of knowledge in contrast to the language knowledge is therefore essential in Prolog programming, Furthermore, even when structured programming knowledge has been correctly applied, various types of programming errors often occur in novice programs. The analysis of these errors therefore presents an effective way of improving a novice's programming skills.

Many attempts have been made to identify and represent structured programming knowledge in Prolog programming, and use it for program construction and transformation. Brna et al (1991), Brna et al (1999) proposed the concept of Prolog programming technique. A Prolog programming technique is a common pattern of code used by the Prolog programmer in a fairly systematic way. In Bowles and Brna (1999) and Bowles et al. (1999), it is shown that knowledge of programming techniques can be useful in both teaching and supporting novice Prolog programmers.

Bundy et al. (1991) described the use of a Prolog programming technique-based approach in the development of a recursive technique editor for Prolog and demonstrated the utility of such an approach for the construction of recursive Prolog procedures. Like the structure editors for the other programming languages, their editor ensures the correctness of the syntax of the procedures. It also ensures that the recursive procedure built by the programmer is guaranteed to terminate and to be well defined.

Gegg-Harrison (1991) discussed the importance of the use of structured programming constructs in Prolog programming. He introduced the notion of basic Prolog construct schemata and showed how they could be used to represent the basic constructs of a structured Prolog for recursive list processing. The basic constructs of Prolog can be treated as common patterns of code and viewed as Prolog programming techniques. Gegg-Harrison (1992), Gegg-Harrison (1993), Gegg-Harrison (1999)) described how the use of program schemata could be incorporated into an intelligent tutoring system for teaching recursive Prolog programming. Since a basic Prolog construct schema represents a Prolog programming technique that is the generalization of a set of programs, it is useful for presenting the general idea of the technique to the student. It is also useful for being presented to the student in the form of program templates for instantiation and modification. A basic Prolog construct schema is, however, less useful for recognizing a student program since it does not provide much grammatical information and relies on pattern matching to match the schema to the student program.

The use of program schemata has been shown to be effective for the optimization of logic programs. A schema-based approach to program transformation was first proposed in Fuchs and Fromherz (1992) and later extended in Vasconcelos and Fuchs (1996) and Richardson and Fuchs (1998) for the optimization of logic programs. In this approach, a set of program schemata is first defined. Transformation schemata are further defined as pairs of program schemata. A transformation schema consisting of a pair of program schemata represents a transformation technique that transforms one program schema in the pair into another. Given a program to be optimized, one of the transformation schemata is selected such that one program schema in it covers the given program under a particular substitution. The same substitution is then applied to another program schema in the transformation schema to create the transformed program.

Schema-based logic program transformation was also studied in Flener and Deville (1996), Buyukyildiz and Flener (1998) and Chasseur and Deville (1998), where the use of transformation schemata for program transformation is similar to that described in Fuchs and Fromherz (1992), Vasconcelos and Fuchs (1996) and Richardson and Fuchs (1998). The main difference is that instead of searching for a transformation schema in which the covering program schema is discovered, a program is synthesized from one program schema in a transformation schema to match the given program. Some further work has been carried out on the correctness of program schemata (Flener et al., 1998) and extensible program schemata (Gegg-Harrison, 1997).

All the above attempts have been mainly focused on facilitating program construction and transformation rather than program debugging and tutoring. Looi (1988), Looi (1991) described an algorithm-based approach to the debugging of the student Prolog program in an intelligent Prolog tutoring system. His system detects errors in the program and proposes the corrections necessary to fix them. Even though Looi showed that his approach to programming debugging is effective, realistic and useful, his work has some limitations. First, the Prolog algorithms are picked up without characterization. Second, all the possible implementations of an algorithm have to be represented. Third, it relies on the representation of buggy versions of programs for error explanation. Finally, it can only give code-related tutoring commentaries to the student.

In this paper, we propose a Prolog programming technique-based approach to the tutoring of Prolog programming. The concept of Prolog programming technique is used to characterize and classify programs. Each class of programs use the same programming technique and share the common pattern of code. Instead of using program schemata, we propose a Prolog programming technique grammar to represent Prolog programming techniques. We define a set of programming technique grammar rules for each class of programs. These programming technique grammar rules can be used for programming technique recognition, program construction and program parsing. The programming technique-related knowledge is represented for each class of programs in a programming technique frame. The coding-related knowledge for the reference program of each most specialized programming technique is represented in a program frame.

The representation of programming technique grammar rules, programming technique-related knowledge and coding-related knowledge provides the basis for guided programming and automated error analysis in tutoring. Our approach to error analysis however does not rely on the representation of buggy versions of the program. Instead of representing all the possible implementations of a program, our approach represents only the standard implementation of the program. The same set of programming technique grammar rules are used to parse both the student program and the standard program. The two parsings are then compared with each other to identify any errors in the student program.

We have incorporated the above approach to guided programming and automated error analysis into an intelligent system for tutoring Prolog programming called the Prolog Tutor. The system first poses a programming exercise to the student and asks him to do the exercise in the form of Prolog program. The system then conducts tutoring in two different modes: guided programming and automated error analysis. The system conducts guided programming when the student is not able to program on his own or has failed to use a programming technique in his program. During guided programming, the student is given directive guidance and provided with program templates in which the relevant programming techniques have been embedded. Under the directive guidance, the student is able to make use of the program templates to program step by step. When the student has shown the correct use of the programming techniques, the tutoring is shifted to error analysis. The system examines the student program, compares it to the standard program for the exercise question, and identifies any errors in it. The student is then given appropriate comments, suggestions or corrections so the errors in his program can be corrected. While the errors are corrected, the student has also learned why the errors have occurred and how they can be corrected so his programming knowledge can be gradually improved.

The paper is organized as follows. In Section 2, we describe the use of Prolog programming techniques to characterize and classify Prolog programs, and the representation of Prolog programming techniques. In Section 3, we describe the representation of the semantic knowledge including programming technique-related and coding-related knowledge, and programming exercises. In Section 4, we present a new approach to the tutoring of Prolog programming on the basis of Prolog programming techniques in which three main tasks, programming technique recognition, guided programming and automated error analysis are involved. In Section 5, we discuss the experimental results of our tests on a collection of 125 program variations. These results show that our Prolog Tutor performs well in terms of programming technique recognition, error detection, and error correction. In Section 6, we compare our work with the related work. In the last section, we summarize the paper and discuss the further developments.

Section snippets

Representing Prolog programming techniques

Many Prolog programs share a common pattern of code. A Prolog programming technique is a common pattern of code used by the Prolog programmer in a fairly systematic way (Brna et al (1991), Brna et al (1999)). Prolog programs can, therefore, be characterized and classified into different categories, with each category of programs corresponding to a particular programming technique. Given a student program, if we can recognize its underlying pattern of code we can know the category of programs it

Representing semantic knowledge and programming exercises

Syntactic knowledge in our Prolog tutor is represented by either programming technique grammar rules for programming techniques at various levels of abstraction, or standard programs at the coding level. Apart from these two types of syntactic knowledge, we also represent semantic knowledge including programming technique-related and coding-related knowledge, and the programming exercises. In this section, we discuss such knowledge representation.

Programming technique recognition, guided programming and error analysis

The tutoring process involves three major tasks: programming technique recognition, guided programming and error analysis. First of all, the system poses a programming exercise to the student by accessing the exercise description in the exercise frame and asks him to write a Prolog program for doing the given task in the exercise. Technique recognition tries to establish whether any programming techniques have been intended by the student. Tutoring focuses can then be found and the system can

Experimental results

We implemented the Prolog Tutor in Prolog and tested it on a collection of 125 programs for the programming exercise, list reversal. In the exercise, the student is asked to write a program, reverse/2, which reverses the elements of a list into another list. This collection of programs were used by Gegg-Harrison (1993), Gegg-Harrison (1994) for testing his Prolog tutoring system called ADAPT. Among these programs, the first 55 programs were originally used by Looi (1988), Looi (1991) for

Related work

To a certain extent, our programming technique-based approach to tutoring Prolog programming resembles McCalla and Greer's granularity-based approach to tutoring Lisp programming (McCalla et al., 1992). Both approaches intend to tutor the student on programming along two dimensions: abstraction and aggregation. Our programming technique hierarchy is similar to McCalla and Greer's principal abstraction hierarchy. In association with each node of a principal abstraction hierarchy, they also have

Variation #18

app([ ], L, L).
app([H|L1], L2, [H|L3]):- append(L1, L2, L3).
reverse([ ], [ ]).
reserve([H|T], Res):- app(Sofar, [H], Res), reverse(T, Sofar).

The Prolog Tutor can recognize straightaway that the naive programming technique has been used in the variation and that the two subgoals in the body of the recursive case of reverse/2 are in the wrong order.

For Variation #32 in the collection as shown below, no transformed normal form program can be found in ADAPT and it is only recognized that the definition

Variation #32

reverse([ ], [ ]).
reserve([H|T], X):- append(X, H, T), reverse(T, Y).

In the Prolog Tutor, though none of the most specialized programming techniques can be recognized as being used in the variation, the list technique at a higher-level of abstraction can however be recognized as being used in the variation. This recognition is very useful in tutoring since there are clearly problems in the use of the subgoal, append(X, H, T), the student should be guided on the use of the list technique and the

Conclusions

In this paper, we discussed how to use Prolog programming techniques to characterize and group together Prolog programs that share the common pattern of code. We described how to use a set of programming technique grammar rules to represent a programming technique, and how to organise these programming techniques in a hierarchical structure called the programming technique hierarchy.

We presented a new approach to the tutoring of Prolog programming to the novice. Different types of frames are

Acknowledgements

The author wishes to thank anonymous reviewers for their insights and helpful comments. This research was in part supported by the centre for software process Technologies (CSPT) at the University of Ulster.

References (30)

  • J.R. Anderson et al.

    The lisp tutor

    Byte

    (1985)
  • Bowles, A., Brna, P., 1999. Introductory Prolog: a suitable selection of programming techniques. In: Brna, P.,...
  • Bowles, A., Robertson, D., Brna, P., 1999. A case-based reasoning approach to supporting novice programmers. In: Brna,...
  • P. Brna et al.

    Prolog programming techniques

    Instructional Science

    (1991)
  • Brna, P., Bundy, A., Dodd, T., et al., 1999. Programming techniques for prolog. In: Brna, P., duBoulay, B., Pain, H....
  • A. Bundy et al.

    A recursive techniques editor for Prolog

    Instructional Science

    (1991)
  • Buyukyildiz, H., Flener, P., 1998. Generalised logic program transformation schemas. In: Fuchs, N.E. (Ed.), Proceedings...
  • Chasseur, E., Deville, Y., 1998. Logic program schemas, constraints and semi-unification. In: Fuchs, N.E. (Ed.),...
  • Flener, P., Deville, Y., 1996. Logic program transformation through generalization schemata. In: Proietti, M. (Ed.),...
  • Flener, P., Lau, K.-K., Ornahgi, M., 1998. On correct program schemas. In: Fuchs, N.E. (Ed.), Proceedings of...
  • Fuchs, N.E., Fromherz, M.P.J., 1992. Schema-based transformations of logic programs. In: Clement, T.P., Lau, K. (Eds.),...
  • T.S. Gegg-Harrison

    Learning Prolog in a schema-based environment

    Instructional Science

    (1991)
  • T.S. Gegg-Harrison

    Adapting instruction to the student's capabilities

    Journal of Artificial Intelligence in Education

    (1992)
  • Gegg-Harrison, T.S., May 1993. Exploiting program schemata in a prolog tutoring system. Ph.D. Dissertation, Technical...
  • T.S. Gegg-Harrison

    Exploiting program schemata in an automated program debugger

    Journal of Artificial Intelligence in Education

    (1994)
  • Cited by (0)

    View full text