program understanding with the lambda calculus - IJCAI

Report 3 Downloads 103 Views
PROGRAM UNDERSTANDING W I T H THE LAMBDA CALCULUS Stanley Letovsky Department of Computer Science Yale University New Haven, CT 06520

ABSTRACT A prerequisite of any a t t e m p t to b u i l d intelligent tools to assist in the programming process is a representation language for encoding programming knowledge. Languages t h a t have been used for this purpose include the predicate calculus [5] and various program-schema languages [1,4]. T h i s paper advocates a new candidate w h i c h is as expressive as the predicate calculus b u t more i n t i m a t e l y connected w i t h programming: the lambda calculus. I t s advantages lie in its close resemblance to convent i o n a l programming languages, and in a straighforward model of inference by r e w r i t i n g , which can be applied to automatic programming and program understanding. T h e use of the lambda calculus in an automatic p r o g r a m understander is described. 1 INTRODUCTION T h e general goal of research in A l / S o f t w a r e Engineering ( A I / S W ) is to construct tools which automate aspects of the software development process t h a t are presently carried out by expert programmers. Such tools need knowledge bases which encode the expertise currently possessed only by programmers. One i m p o r t a n t category of programming knowledge is the standard plans of p r o g r a m m i n g : this category includes algorithms, data structures and associated operations, and simple cliches such as summing and counting. T h i s paper describes an approach to n o t a t i n g these plans, and to performing mechanical inference w i t h t h e m . II METHODS OF REPRESENTING PLANS One m i g h t t h i n k t h a t a programming language would suffice to notate the plans used by programmers: after a l l , programming languages are languages for notating programming k n o w l edge. There are t w o problems w i t h this idea. F i r s t , the syntax and semantics of programming languages tends to be rather t o o clunky and complex for the needs of mechanical inference. More i m p o r t a n t l y , the types of composition of concepts supported by programming languages, via language constucts such as subroutines, packages, abstract data types, or objects, correspond to only a subset of the ways t h a t concepts can combine in a programmer's m i n d . These l i m i t a t i o n s on the expressivity of programming languages have led A I / S W researchers to use more expressive languages for w r i t i n g d o w n the knowledge. These include a v a r i ety of p r o g r a m schema languages and the predicate calculus. A schema language (eg.,[4,1]) is usually a programming language of 1

512

T h l i research was supported by NSF under 1ST grant #8505019.

KNOWLEDGE REPRESENTATION

some sort augmented w i t h pattern-matching variables. Plans are represented as incomplete programs, w i t h variable parts. T h i s approach lends itself well to syntactic matching on programs w r i t t e n in the base programming language, b u t the reasoning is subject to various types of errors, because the syntactic patt e r n matching can generate semantic nonsense. In particular, schema variables can be instantiated w i t h code segments w h i c h destroy the dataflow relationships assumed by other parts of the schema.

Letovsky

513

References [l] David Barstow. Knowledge-Based Program Construction. Elsevier North Holland Inc., 1979. [2] Robert S. Boyer and J. Strother Moore. A Computational Logic. Academic Press, 1979. [3] Alonio Church. The calculi of lambda conversion. Annals of Mathematical Studies, 6, 1951. [4] W. L. Johnson and E. Soloway. Proust: knowledge-based program understanding. In Proceedings of the 7th International Conference on Software Engineering, IEEE, Orlando, Florida, 1983. [5] Charles Rich. A formal representation of plans for the programmer's apprentice. In Proceedings of the Seventh International Joint Conference on Artificial Intelligence, pages 1044-1053, IJCAI, Vancouver, B.C., 1981. [6] Charles Rich. Inspection Methods in Programming. Technical Report AI-TR-604, MIT AI Lab, 1981. [7] Stephen Slade. The T Programming Language: A Dialect of LISP. Prentice Hall Inc., 1987. [8] Guy Lewis Steele and Gerald Jay Sunman. The Revised Report on SCHEME, a Dialect of LISP. Technical Report AI-Memo452, MIT AI Lab, January 1978. (9] Joseph E. Stoy. Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory. The MIT Press, 1977. [10] Richard C. Waters. A method for analysing loop programs. IEEE Transactions on Software Engineering, SE-5(3):237-247, 1979.

514

KNOWLEDGE REPRESENTATION