Elements of Programming Linguistics. Part I, the Lambda Calculus and Its

Elements of Programming Linguistics. Part I, the Lambda Calculus and Its

U3P4HY TECHNICAL REPORT SFCTION POSTGRADUATE SCHOOL MONTEREY, CALIFORNIA 9394Q NPS52-81-012 NAVAL POSTGRADUATE SCHOOL Monterey, California ELEMENTS OF PROGRAMMING LINGUISTICS Part I The Lambda Calculus and its Implementation B. J. MacLennan Naval Postgraduate School copyright 1981 Approved for public release; distribution unlimited Prepared for: Naval Postgraduate School Monterey, California 93940 FEDDOCS D 208.14/2:NPS-52-81-012 NAVAL POSTGRADUATE SCHOOL Monterey, California Rear Admiral J. J. Ekelund D. A. Schrady Superintendent Acting Provost The work reported herein was supported by the Foundation Research Program of the Naval Postgraduate School with funds provided by the Chief of Naval Research. Reproduction of all or part of this report is authorized. Thic ronnrt wa<; Dreoared bv: Unclassified SECURITY CLASSIFICATION OF THIS PAGE 'When Data Entered) READ INSTRUCTIONS REPORT DOCUMENTATION PAGE BEFORE COMPLETING FORM 1 REPORT NUMBER 2. GOVT ACCESSION NO.I 3. RECIPIENTS CATALOG NUMBER NPS52-81-012 4. TITLE 'and Subtitle} 5. TYPE OF REPORT S PERIOO COVERED ELEMENTS OF PROGRAMMING LINGUISTICS Part I Technical Report The Lambda Calculus and its Implementation 5 PERFORMING ORG. REPORT NUMBER 7. AUTHORCjj 9. CONTRACT OR GRANT NUMBERf»J Bruce J. MacLennan 9. PERFORMING ORGANIZATION NAME AND ADDRESS 10. PROGRAM ELEMENT. PROJECT, TASK AREA 4 WORK UNIT NUMBERS Naval Postgraduate School Monterey, CA 93940 61152N; rrOOO-01-10 N0001481WR10034 H. CONTROLLING OFFICE NAME ANO ADORESS 12. REPORT DATE 13 August 1981 Naval Postgraduate School 13. NUMBER OF =AGES Monterey, CA 93940 14. MONITORING AGENCY NAME 4 ADORESSr// dlflerent !rom Controlling Olllce) 15. SECURITY CLASS, 'ol thla report) Unclassified 1S«. DECLASSIFICATION- DOWNGRADING SCHEDULE 16. DISTRIBUTION STATEMENT ol thla Report) Approved for public release; distribution unlimited 17. DISTRIBUTION STATEMENT (ol the abatract entered In Block 20, // dlllerent from Report) 18. SUPPLEMENTARY NOTES 19. KEY WORDS (Continue on reverse aide It neceaaary and Identity by block number) lambda calculus, LISP, block structured languages, list processing, interpreters, stack implementation, reduction, translation 20. ABSTRACT (Continue on reverse aide It neceaaary and identify by block number) The lambda calculus is used as an introduction to programming language concepts, particularly the concepts of functional programming. Both inter- preted and compiled implementations of an extended lambda calculus are dis- cussed. They can be adopted to implementations of Pascal and Lisp it is shown that traditional stack-based run-time structures can be directly derived from the reduction rules of the lambda calculus. EDITION OF I NOV 6S IS OBSOLETE DO I jan 73 1473 S/N 0102-014- 6601 Unci assi fed SECURITY CLASSIFICATION OF THIS PAGE (When Data Bnfrad) . .. m - 1 - TABLE 0_F CONTENTS I. THE LAMBDA CALCULUS AND ITS IMPLEMENTATION 1 Introduction 2 The L a i.i b da Calculus This chapter introduces the important concepts of bound and free variaole, and scope, as embodied in the lambda calculus. The reduction rules of the lambda calculus are explained with a number of examples. 1 calculus defined 2. bound variables defined 3. bound and free occurences, and scope 4. renaming bound variables 5. function definition 6. syntax of the lam baa calculus 7. semantics of the lambda calculus 8. reduced form 9. multiple parameters and other abbreviations 10. the Church-Rosser property 3. The Extended Lambda Calculus In this chapter the la bda calculus is turned into a practical LISP-like programming language through the introducton of conditionals, arithmetic operations, - list manipulation operations and 1 et and where d e c 1 a r a tions. These are illustrated through examples. The idea of an absract data type is introduced and used as a framework for explaining the list data type. 1 cond i t i onal s 2. recursive definitions .. 3 . primitives 4. data types 5. the list data type 6. recursive problem solving 7 sy nt act i c sugar 8. local declarations in mathematical prose 9. local declarations in the lambda calculus 10. terminology 11. compound declarations 12. recursive declarations 4. Implementing the Lambda Calculus This chapter develops a recursive interpreter for the lambda calculus. It is similar to the traditional EVAL interpreter for LISP. The structure of this interpreter is motivated by deriving it in a series of simple steps from the hand-reduction procedures presented in Chapter 2. The important concepts of clo- sures and association lists are introduced. This chapter finishes by discussing the elimination of the run -time looKup of variables. This leads to the ideas ( of i p , e p ) pairs, static nesting levels and static dis- tances. Contour diagrams are used to clarify these concepts. This material prepares the ground for the discussion of static chains in Chapter 5. 1 goals def i ned 2. mechanical reduction 3 context 4. hand eval uat i on 5 constants 6. variables 7. abstractions .. 3 _ 8. applications 9. primitive applications 10. conditionals 11. example of hand evaluation 12. representation defined 13. field accessing functions 14. association lists 15 cl osures 16. mechanical evaluation 17. representation of variables by fixed locations 18. static nesting level 19. multiple parameters 5. Runtime Organization Chapter 5 develops an implementation of the extended lambda calculus for a conventional computer. As preliminaries the ideas of stacks and postfix instructions dre explained. This simplifies the expla- nation of the L- machine, a simplified postfix-oriented stack computer. This material provides the background for a first cut at a compiled implementation of the extended lambda calculus. The ideas of activation records and static chains are explained and derived from the simple interpreter described in Chapter 4. This allows the development of L-code sequences for each ELC (extended lambda calculus) construct. 1. goals defined 2 stacks 3. postfix instructions 4. the L-machine architecture 5. activation record structure . 6. translation to L-code 1 constants 2. primitive applications 3. variables 4. applications 5 . ab st ract ions 6. conditionals 7 blocks , - 5 - Chapter 1 1 . 1 I nt roduct i on Ther ear e s e v eral rea sons tha t th e lam bda c al cu 1 us is l in por- tant for de sign er s a nd i mp 1 erne nt or s of progr a mini ng 1 angua ges . One o f th e fi rst uses of t he 1 a in b d a ca 1 cul u s as a t ool of pro- gramm i ng 1 in gui s tics occ u rred i n the mid 1 960s when Str achey and - L a n d i n us ed i t to el u c i da te the sem antic s of Al gol 60. The 1 ambd a c al cu 1 us was pick ed b ec au s e as we shal 1 se e, i t has the same scop e ru les as bl ock st r uct u red 1 ang uag es • This al 1 owed the cons eque nc es oft hese ru 1 es t o be stud i ed i n a di st ill ed and s i mpl e co nt ex t. In pa rt i c ul ar , th i s a 1 1 owe d th e i mpl e ment a t i on of bl ock st ru ct ur ed 1 a ngua ges to b e i n v e s t i gat ed wi t hout the corn- " 1" pi ex i t i es of rea la ngua g es . In thi s man ua 1 y ou w ill s ee both - i nter pret ed a nd c o in p i 1 ed i mpl e m e n t at i o ns of the 1 amb da c al cul us s emi n al t echn i qu e s t ha tea n b e use d or ada pt ed for ma ny o ther 1 angu ages For i nst a nee , th e c_l_ os ur e i mp 1 emen tat i one oncep t i s " i i m p o r tant n u nd e rstan di ng cor out i nes , proc ess es an d t he 1 azy eval u at i o n" t echn i q u e s di s cuss ed i n Pa rt I I The symmetry and simplicity of the lambda calculus sets a standard against which all languages can be compared. For instance, the essential equivalence between formal parameters and declarations in the lamoda calculus suggests a solution to many problems of language design. This has been used in several experimental languages, e.g. Quest. Although the lambda calculus is capable of computing any computable function, it provides a model of computation that is much closer to real languages than most other such models (e.g. Markov algorithms, Turing machines, recursive functions). It is therefore more relevent to the real problems of language design. The programming practices and modes of thought used with the lambda calculus and its derivatives (such as LISP) have formed the foundation of f unct i o nal programmi ng - the method of program- ming recently popularized by Backus and characterized by a high- level applicative programming style. The lambda calculus is essential for an understanding of the design and implementation of such 1 anguages . , . t . Chapter 2 1.2 The Lambda Calculus 1.2.1 calculus define^ we wi 11 be usi ng the 1 ambda calculus as a model of comouta- tion. Th at is , we will be usi ng the lambda ca leulu s as a way of describing the mean inq of p rogr ams and as a guide to th e imple- is a mentation of prog ramming Ian auages ^ SL alculus notation which can be manipu lated me chan ica lly to ach leve som e en d.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    98 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us