• Simple Syntax and Semantics • John Mccarthy's Original Lisp Had Very

Total Page:16

File Type:pdf, Size:1020Kb

• Simple Syntax and Semantics • John Mccarthy's Original Lisp Had Very • Implementing a language is a good way to learn more about programming languages • Interpreters are easier to implement than compilers, in general • Scheme is a simple language, but also a powerful one • Implementing it first in Scheme allows us to put off some of the more complex lower-level parts, like parsing and data structures • While focusing on higher-level aspects • Simple syntax and semantics • “A meta-circular evaluator is a special • John McCarthy’s original Lisp had very case of a self-interpreter in which the little structure: existing facilities of the parent interpreter • Procedures CONS, CAR, CDR, EQ and are directly applied to the source code ATOM being interpreted, without any need for • Special forms QUOTE, COND, SET and additional implementation. Meta-circular LAMBDA evaluation is most common in the • Values T and NIL context of homoiconic languages”. • The rest of Lisp can be built on this • We’ll look at an adaptation from foundation (more or less) Abelson and Sussman,Structure and Interpretation of Computer Programs, MIT Press, 1996. 1 • Homoiconicity is a property of some programming languages • We’ll not do all of Scheme, just enough • From homo meaning the same and icon for you to understand the approach meaning representation • We can us the same approach for an • A programming language is homoiconic interpreter for Scheme in Python if its primary representation for programs • To provide reasonable efficiency, we’ll is also a data structure in a primitive use mutable-pairs type of the language itself • Few examples: Lisp, Prolog, Snobol • Scheme calls a cons cell a pair GL% clisp [5]> l2 • Lisp always had special functions to ... (FOO B) change (aka destructively modify or [1]> (setq l1 '(a b)) [6]> (rplacd l1 '(2 3 4)) mutate) the components of a simple cons cell (A B) (FOO 2 3 4) • Can you detect a sentiment there? [2]> (setq l2 l1) [7]> l1 • RPLACA (RePLAce CAr) was Lisp’s function (A B) (FOO 2 3 4) to replace the car of a cons cell with a new [3]> (rplaca l2 'foo) [8]> l2 pointer (FOO B) (FOO 2 3 4) • RPLACD (RePLAce CDr) clobbered the cons cell’s cdr pointer [4]> l1 (FOO B) 2 > (define l1 '(a b c d)) > (set-cdr! l1 l1) • Scheme removed set-car! and set-cdr! from > l1 > l1 the language as of R6RS • They played to their ideological base here (a b c d) #0=(foo . #0#) • Or maybe just eating their own dog food > (set-car! l1 'foo) > (cadr l1) foo • R6RS is the Revised **6 Report on the > l1 Algorithmic Language Scheme > (caddr l1) R6RS does have a library, mutable-pairs, (foo b c d) foo • provides a new datatype for a mutable pair > (set-cdr! l1 '(2 3)) > (cadddr l1) and functions for it > l1 foo • mcons, mcar, mcdr, mlist, …set-mcar!, set- (foo 2 3) mcdr! • Some languages are created/promoted by a • Scheme is standardized in the official company (e.g., Sun:Java, Microsoft:F#, IEEE standard and via a de facto Apple:Objective C) standard called the Revisedn Report on • But for a language to really be accepted, it the Algorithmic Language Scheme should be defined and maintained by the community • Or RnRS • And backed by a well-defined standard • Common versions: • That may be supported by a recognized • R5RS in 1998 standards organizations (e.g., IEEE, ANSI, • R6RS in 2007 W3C, etc) 3 > (define l1 (cons 1 (cons 2 empty))) > (mcar m1) > l1 1 • We’ll sketch out some rules to use in (1 2) > (set-car! l1 'foo) . reference to undefined identifier: evaluating an s-expession > (define m1 (mcons 1 (mcons 2 set-car! empty))) > (set-mcar! l1 'foo) • Then realize them in Scheme > m1 . set-mcar!: expects type <mutable- {1 2} pair> as 1st argument, given: (1 2); • The (only) tricky part is representing an > (car l1) other arguments were: foo environment: binding symbols to values 1 > (set-mcar! m1 'foo) > m1 • Environments inherit from other > (car m1) {foo 2} . car: expects argument of type environments, so we’ll consider an <pair>; given {1 2} environment to be a set of frames • We’ll start with a global environment • An environment is just a list of frames • An environment frame is just an • The first frame is the current (unordered) collection of bindings environment, the second is the one it • A binding has two elements: a symbol inherits from, the third is the one the representing a variable and an object second inherits from, etc. representing its (current) value • The last frame is the global or top level • An environment might be represented as environment ( ( (x 100) (y 200) ) ( (a 1) (b 2) (x 2) ) ( (null ‘()) (empty ‘()) (cons …) …) ) 4 Special forms are those that get evaluated • Self-Evaluating - Just return their value in a special, non-standard way • Numbers and strings are self • (quote X) – return X evaluating • (define X B) – bind X to evaluation of B • (lambda VARS BODY) - Make a procedure, • Symbol - Lookup closest binding in the write down VARS and BODY, do not evaluate current environment and return its • (set! X Y) – find X binding name, eval Y and set second element X to the return value • Raise an error if not found • (if X Y Z) – eval X and then eval either Y or Z • Primitive: (F . ARGS) • We’re implementing an interpreter for • Apply by magic... Scheme in Scheme • User-defined: (F . ARGS) • The host language (Scheme) will do many details: data representation, reading, • Make a new environment frame printing, primitives (e.g., cons, car, +) • Extend to procedures frame • Our implementation will focus on a few • Bind arguments to formal parameters key parts: eval, apply, variables and • Evaluate procedure body in the new environments, user defined functions, etc. frame • Return its value 5 http://cs.umbc.edu/331/f11/code/scheme/mcs/ • define can only assign a variable to a value, i.e., 1st arg must be a symbol. • mcs.ss: simple Scheme subset Define functions like: • mcs_scope.ss: larger Scheme subset (define add1 (lambda (x) (+ x 1)) • mcs_basics.ss: 'library' of basic • lambda only allows one expression in functions body; for more use begin: (lambda (x) (begin (define y (* x x)) (* y y))) • readme.txt: short intro text • No set! to assign variables outside of the • session.txt: example of McScheme in local environment (e.g., global variables) use Here’s a trivial read-eval-print loop: (define (mcscheme) ;; mcscheme read-eval-print loop (printf "mcscheme> ") (mcprint (mceval (read) global-env)) (mcscheme)) (define (mcprint x) ;; Top-level print: print x iff it's not void (or (void? x) (printf "~s~n" x))) The eval and apply operations have been fundamental from the start 6 (define (mceval exp env) (define (mcapply op args) (cond ((self-evaluating? exp) exp) (if (primitive? op) ((symbol? exp) (lookup exp env)) (do-magic op args) ((special-form? exp) (mceval (op-body op) (do-something-special exp env)) (extend-environment (else (mcapply (mceval (car exp) env) (op-formals op) (map (lambda (e) (mceval e env)) args (cdr exp))) ) ) ) (op-env op))))) • In Scheme or Lisp, the representation of a • An environment is just a list of environment function has three parts: frames • A list of the names of its formal parameters • The last frame in the list is the global one • The expression(s) that make up the • The nth frame in the list extends the n+1th function’s body, i.e. the code to be evaluated • An environment frame records two things • The environment in which the function was • A list of variables bound in the environment defined, so values of non-local symbols can • The values they are bound to be looked up • Suppose we want to extend the global environ- • We might just represent a function as a list like ment with a new local one where x=1 and y=2 (procedure (x y) (+ (* 2 x) y) (… env …)) 7 • Consider entering: • Consider entering: (define foo 100) (square foo) (define square (lambda (x) (* x x))) • mcscheme evaluates square and foo in (define x -100) the current environment and pushes a new • The environment after evaluating the first frame onto the environment in which x is three expressions would look like: bound to 100 ( ( (x . -100) ( (( x . 100 )) (square lambda (x)(* x x )) ((x . -100) (foo . 100) (square lsmbda (x)(* x x )) …) (foo . 100) ... ) ) ) (define (mceval exp env) (cond ((self-evaluating? exp) exp) ((symbol? exp) (lookup-variable-value exp env)) ((quoted? exp) (cadr exp)) ((assignment? exp) (eval-assignment exp env)) ((definition? exp) (eval-definition exp env)) ((if? exp) (eval-if exp env)) Take a look at the handout ((lambda? Exp) (make-procedure (cadr exp) (cddr exp) env)) ((begin? exp) (eval-sequence (cdr exp) env)) ((application? exp) (mcapply (mceval (car exp) env) (map (lambda (x)(mceval x env)) (cdr exp)))) (else (error "mceval: Unknown expression type" exp)))) 8 (define (mcapply procedure arguments) (cond ((primitive-procedure? procedure) (define global-environment '()) (apply-primitive-procedure procedure arguments)) ((defined-procedure? procedure) (define (setup-environment) (eval-sequence (let ((initial-env (proc-body procedure) (extend-environment primitive-proc-names (extend-environment primitive-proc-objects (proc-parameters procedure) the-empty-environment))) arguments (define-variable! 'empty '() initial-env) (proc-environment procedure)))) initial-env)) (else (error "mceval: Unknown proc. type" procedure)))) (define the-global-environment (setup-environment)) (define (lookup-variable-value var env) (define (env-loop env) (define (scan vars vals) (define (extend-environment vars vals base-env) (cond ((null? vars) (if (= (length vars) (length vals)) (env-loop (enclosing-environment env))) (cons (make-frame vars vals) base-env) ((eq? var (car vars))
Recommended publications
  • Preview Objective-C Tutorial (PDF Version)
    Objective-C Objective-C About the Tutorial Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. This is the main programming language used by Apple for the OS X and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch. This reference will take you through simple and practical approach while learning Objective-C Programming language. Audience This reference has been prepared for the beginners to help them understand basic to advanced concepts related to Objective-C Programming languages. Prerequisites Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program, and what is a computer programming language? Copyright & Disclaimer © Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book can retain a copy for future reference but commercial use of this data is not allowed. Distribution or republishing any content or a part of the content of this e-book in any manner is also not allowed without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] ii Objective-C Table of Contents About the Tutorial ..................................................................................................................................
    [Show full text]
  • Algorithms and Data Structures Lecture 11: Symbol Table ADT
    cs2010: algorithms and data structures Lecture 11: Symbol Table ADT Vasileios Koutavas School of Computer Science and Statistics Trinity College Dublin Algorithms ROBERT SEDGEWICK | KEVIN WAYNE 3.1 SYMBOL TABLES ‣ API ‣ elementary implementations Algorithms ‣ ordered operations FOURTH EDITION ROBERT SEDGEWICK | KEVIN WAYNE http://algs4.cs.princeton.edu 3.1 SYMBOL TABLES ‣ API ‣ elementary implementations Algorithms ‣ ordered operations ROBERT SEDGEWICK | KEVIN WAYNE http://algs4.cs.princeton.edu Symbol tables Key-value pair abstraction. ・Insert a value with specified key. ・Given a key, search for the corresponding value. Ex. DNS lookup. ・Insert domain name with specified IP address. ・Given domain name, find corresponding IP address. domain name IP address www.cs.princeton.edu 128.112.136.11 www.princeton.edu 128.112.128.15 www.yale.edu 130.132.143.21 www.harvard.edu 128.103.060.55 www.simpsons.com 209.052.165.60 key value 3 Symbol table applications application purpose of search key value dictionary find definition word definition book index find relevant pages term list of page numbers file share find song to download name of song computer ID financial account process transactions account number transaction details web search find relevant web pages keyword list of page names compiler find properties of variables variable name type and value routing table route Internet packets destination best route DNS find IP address domain name IP address reverse DNS find domain name IP address domain name genomics find markers DNA string known positions file system find file on disk filename location on disk 4 Symbol tables: context Also known as: maps, dictionaries, associative arrays.
    [Show full text]
  • The Machine That Builds Itself: How the Strengths of Lisp Family
    Khomtchouk et al. OPINION NOTE The Machine that Builds Itself: How the Strengths of Lisp Family Languages Facilitate Building Complex and Flexible Bioinformatic Models Bohdan B. Khomtchouk1*, Edmund Weitz2 and Claes Wahlestedt1 *Correspondence: [email protected] Abstract 1Center for Therapeutic Innovation and Department of We address the need for expanding the presence of the Lisp family of Psychiatry and Behavioral programming languages in bioinformatics and computational biology research. Sciences, University of Miami Languages of this family, like Common Lisp, Scheme, or Clojure, facilitate the Miller School of Medicine, 1120 NW 14th ST, Miami, FL, USA creation of powerful and flexible software models that are required for complex 33136 and rapidly evolving domains like biology. We will point out several important key Full list of author information is features that distinguish languages of the Lisp family from other programming available at the end of the article languages and we will explain how these features can aid researchers in becoming more productive and creating better code. We will also show how these features make these languages ideal tools for artificial intelligence and machine learning applications. We will specifically stress the advantages of domain-specific languages (DSL): languages which are specialized to a particular area and thus not only facilitate easier research problem formulation, but also aid in the establishment of standards and best programming practices as applied to the specific research field at hand. DSLs are particularly easy to build in Common Lisp, the most comprehensive Lisp dialect, which is commonly referred to as the “programmable programming language.” We are convinced that Lisp grants programmers unprecedented power to build increasingly sophisticated artificial intelligence systems that may ultimately transform machine learning and AI research in bioinformatics and computational biology.
    [Show full text]
  • From JSON to JSEN Through Virtual Languages of the Creative Commons Attribution License (
    © 2021 by the authors; licensee RonPub, Lübeck, Germany. This article is an open access article distributed under the terms and conditions A.of Ceravola, the Creative F. Joublin:Commons From Attribution JSON to license JSEN through(http://c reativecommons.org/licenses/by/4Virtual Languages .0/). Open Access Open Journal of Web Technology (OJWT) Volume 8, Issue 1, 2021 www.ronpub.com/ojwt ISSN 2199-188X From JSON to JSEN through Virtual Languages Antonello Ceravola, Frank Joublin Honda Research Institute Europe GmbH, Carl Legien Str. 30, Offenbach/Main, Germany, {Antonello.Ceravola, Frank.Joublin}@honda-ri.de ABSTRACT In this paper we describe a data format suitable for storing and manipulating executable language statements that can be used for exchanging/storing programs, executing them concurrently and extending homoiconicity of the hosting language. We call it JSEN, JavaScript Executable Notation, which represents the counterpart of JSON, JavaScript Object Notation. JSON and JSEN complement each other. The former is a data format for storing and representing objects and data, while the latter has been created for exchanging/storing/executing and manipulating statements of programs. The two formats, JSON and JSEN, share some common properties, reviewed in this paper with a more extensive analysis on what the JSEN data format can provide. JSEN extends homoiconicity of the hosting language (in our case JavaScript), giving the possibility to manipulate programs in a finer grain manner than what is currently possible. This property makes definition of virtual languages (or DSL) simple and straightforward. Moreover, JSEN provides a base for implementing a type of concurrent multitasking for a single-threaded language like JavaScript.
    [Show full text]
  • The Semantics of Syntax Applying Denotational Semantics to Hygienic Macro Systems
    The Semantics of Syntax Applying Denotational Semantics to Hygienic Macro Systems Neelakantan R. Krishnaswami University of Birmingham <[email protected]> 1. Introduction body of a macro definition do not interfere with names oc- Typically, when semanticists hear the words “Scheme” or curring in the macro’s arguments. Consider this definition of and “Lisp”, what comes to mind is “untyped lambda calculus a short-circuiting operator: plus higher-order state and first-class control”. Given our (define-syntax and typical concerns, this seems to be the essence of Scheme: it (syntax-rules () is a dynamically typed applied lambda calculus that sup- ((and e1 e2) (let ((tmp e1)) ports mutable data and exposes first-class continuations to (if tmp the programmer. These features expose a complete com- e2 putational substrate to programmers so elegant that it can tmp))))) even be characterized mathematically; every monadically- representable effect can be implemented with state and first- In this definition, even if the variable tmp occurs freely class control [4]. in e2, it will not be in the scope of the variable definition However, these days even mundane languages like Java in the body of the and macro. As a result, it is important to support higher-order functions and state. So from the point interpret the body of the macro not merely as a piece of raw of view of a working programmer, the most distinctive fea- syntax, but as an alpha-equivalence class. ture of Scheme is something quite different – its support for 2.2 Open Recursion macros. The intuitive explanation is that a macro is a way of defining rewrites on abstract syntax trees.
    [Show full text]
  • A History of Clojure
    A History of Clojure RICH HICKEY, Cognitect, Inc., USA Shepherd: Mira Mezini, Technische Universität Darmstadt, Germany Clojure was designed to be a general-purpose, practical functional language, suitable for use by professionals wherever its host language, e.g., Java, would be. Initially designed in 2005 and released in 2007, Clojure is a dialect of Lisp, but is not a direct descendant of any prior Lisp. It complements programming with pure functions of immutable data with concurrency-safe state management constructs that support writing correct multithreaded programs without the complexity of mutex locks. Clojure is intentionally hosted, in that it compiles to and runs on the runtime of another language, such as the JVM. This is more than an implementation strategy; numerous features ensure that programs written in Clojure can leverage and interoperate with the libraries of the host language directly and efficiently. In spite of combining two (at the time) rather unpopular ideas, functional programming and Lisp, Clojure has since seen adoption in industries as diverse as finance, climate science, retail, databases, analytics, publishing, healthcare, advertising and genomics, and by consultancies and startups worldwide, much to the career-altering surprise of its author. Most of the ideas in Clojure were not novel, but their combination puts Clojure in a unique spot in language design (functional, hosted, Lisp). This paper recounts the motivation behind the initial development of Clojure and the rationale for various design decisions and language constructs. It then covers its evolution subsequent to release and adoption. CCS Concepts: • Software and its engineering ! General programming languages; • Social and pro- fessional topics ! History of programming languages.
    [Show full text]
  • Star TEX: the Next Generation Several Ideas on How to Modernize TEX Already Exist
    TUGboat, Volume 33 (2012), No. 2 199 Star TEX: The Next Generation Several ideas on how to modernize TEX already exist. Some of them have actually been implemented. Didier Verna In this paper, we present ours. The possible future Abstract that we would like to see happening for TEX is some- what different from the current direction(s) TEX's While T X is unanimously praised for its typesetting E evolution has been following. In our view, modern- capabilities, it is also regularly blamed for its poor izing TEX can start with grounding it in an old yet programmatic offerings. A macro-expansion system very modern programming language: Common Lisp. is indeed far from the best choice in terms of general- Section 2 clarifies what our notion of a \better", or purpose programming. Several solutions have been \more modern" TEX is. Section 3 on the next page proposed to modernize T X on the programming E presents several approaches sharing a similar goal. side. All of them currently involve a heterogeneous Section 4 on the following page justifies the choice approach in which T X is mixed with a full-blown pro- E of Common Lisp. Finally, section 5 on page 205 gramming language. This paper advocates another, outlines the projected final shape of the project. homogeneous approach in which TEX is first rewrit- ten in a modern language, Common Lisp, which 2 A better TEX serves both at the core of the program and at the The T X community has this particularity of being scripting level. All programmatic macros of T X are E E a mix of two populations: people coming from the hence rendered obsolete, as the underlying language world of typography, who love it for its beautiful itself can be used for user-level programming.
    [Show full text]
  • Specialising Dynamic Techniques for Implementing the Ruby Programming Language
    SPECIALISING DYNAMIC TECHNIQUES FOR IMPLEMENTING THE RUBY PROGRAMMING LANGUAGE A thesis submitted to the University of Manchester for the degree of Doctor of Philosophy in the Faculty of Engineering and Physical Sciences 2015 By Chris Seaton School of Computer Science This published copy of the thesis contains a couple of minor typographical corrections from the version deposited in the University of Manchester Library. [email protected] chrisseaton.com/phd 2 Contents List of Listings7 List of Tables9 List of Figures 11 Abstract 15 Declaration 17 Copyright 19 Acknowledgements 21 1 Introduction 23 1.1 Dynamic Programming Languages.................. 23 1.2 Idiomatic Ruby............................ 25 1.3 Research Questions.......................... 27 1.4 Implementation Work......................... 27 1.5 Contributions............................. 28 1.6 Publications.............................. 29 1.7 Thesis Structure............................ 31 2 Characteristics of Dynamic Languages 35 2.1 Ruby.................................. 35 2.2 Ruby on Rails............................. 36 2.3 Case Study: Idiomatic Ruby..................... 37 2.4 Summary............................... 49 3 3 Implementation of Dynamic Languages 51 3.1 Foundational Techniques....................... 51 3.2 Applied Techniques.......................... 59 3.3 Implementations of Ruby....................... 65 3.4 Parallelism and Concurrency..................... 72 3.5 Summary............................... 73 4 Evaluation Methodology 75 4.1 Evaluation Philosophy
    [Show full text]
  • Language Design and Implementation Using Ruby and the Interpreter Pattern
    Language Design and Implementation using Ruby and the Interpreter Pattern Ariel Ortiz Information Technology Department Tecnológico de Monterrey, Campus Estado de México Atizapán de Zaragoza, Estado de México, Mexico. 52926 [email protected] ABSTRACT to explore different language concepts and programming styles. In this paper, the S-expression Interpreter Framework (SIF) is Section 4 describes briefly how the SIF has been used in class. presented as a tool for teaching language design and The conclusions are found in section 5. implementation. The SIF is based on the interpreter design pattern and is written in the Ruby programming language. Its core is quite 1.1 S-Expressions S-expressions (symbolic expressions) are a parenthesized prefix small, but it can be easily extended by adding primitive notation, mainly used in the Lisp family languages. They were procedures and special forms. The SIF can be used to demonstrate selected as the framework’s source language notation because advanced language concepts (variable scopes, continuations, etc.) they offer important advantages: as well as different programming styles (functional, imperative, and object oriented). • Both code and data can be easily represented. Adding a new language construct is pretty straightforward. • Categories and Subject Descriptors The number of program elements is minimal, thus a parser is − relatively easy to write. D.3.4 [Programming Languages]: Processors interpreters, • run-time environments. The arity of operators doesn’t need to be fixed, so, for example, the + operator can be defined to accept any number of arguments. General Terms • There are no problems regarding operator precedence or Design, Languages. associativity, because every operator has its own pair of parentheses.
    [Show full text]
  • Symbolic Programming Example
    CS 580 1 ' $ Symb olic Programming Symb ols: +, -, 1, 2 etc. Symb olic expressions: + 1 2, + * 3 4 2 Symb olic programs are programs that manipulate symbolic expressions. Symb olic manipulation: you do it all the time; now you'll write programs to do it. & CS 580 2 ' $ Example Logical rules can be represented as symb olic expressions of the form, `antecedent' implies `consequent'. The following rule states that the relation of `b eing inside something is transitive, `x is inside y and yis inside z' implies `x is inside z'. In lisp notation, we would represent this rule as setq rule `implies and inside x y inside y z inside x z & CS 580 3 ' $ Manipulating symb olic expressions rst rule ;; The expression is a rule. ;; FIRST RULE ! IMPLIES second rule ;; The antecedent of the rule. ;; SECOND RULE! AND INSIDE X Y INSIDE Y Z third rule ;; The consequent of the rule. ;; THIRD RULE ! INSIDE X Z rst second rule ;; The antecedent is a conjunction. ;; FIRST SECOND RULE ! AND second second rule ;; The rst conjunct of the antecedent. ;; SECOND SECOND RULE ! INSIDE X Y & CS 580 4 ' $ Lisp and Common Lisp What are you lo oking for in a programming language? primitive data typ es: strings, numbers, arrays op erators: +, -, +, /, etc. ow of control: if, or, and, while, for input/output: le handling, loading, compiling programs & CS 580 5 ' $ Lisp has all of this and more. develop ed by John McCarthy at MIT second oldest programming language still in use FORTRAN is oldest sp eci cally designed for symb olic programming We use a dialect of Lisp called Common Lisp.
    [Show full text]
  • An Introduction to Prolog
    Appendix A An Introduction to Prolog A.1 A Short Background Prolog was designed in the 1970s by Alain Colmerauer and a team of researchers with the idea – new at that time – that it was possible to use logic to represent knowledge and to write programs. More precisely, Prolog uses a subset of predicate logic and draws its structure from theoretical works of earlier logicians such as Herbrand (1930) and Robinson (1965) on the automation of theorem proving. Prolog was originally intended for the writing of natural language processing applications. Because of its conciseness and simplicity, it became popular well beyond this domain and now has adepts in areas such as: • Formal logic and associated forms of programming • Reasoning modeling • Database programming • Planning, and so on. This chapter is a short review of Prolog. In-depth tutorials include: in English, Bratko (2012), Clocksin and Mellish (2003), Covington et al. (1997), and Sterling and Shapiro (1994); in French, Giannesini et al. (1985); and in German, Baumann (1991). Boizumault (1988, 1993) contain a didactical implementation of Prolog in Lisp. Prolog foundations rest on first-order logic. Apt (1997), Burke and Foxley (1996), Delahaye (1986), and Lloyd (1987) examine theoretical links between this part of logic and Prolog. Colmerauer started his work at the University of Montréal, and a first version of the language was implemented at the University of Marseilles in 1972. Colmerauer and Roussel (1996) tell the story of the birth of Prolog, including their try-and-fail experimentation to select tractable algorithms from the mass of results provided by research in logic.
    [Show full text]
  • Rubywrite: a Ruby-Embedded Domain-Specific Language for High-Level Transformations
    RubyWrite: A Ruby-Embedded Domain-Specific Language for High-Level Transformations Andrew Keep, Arun Chauhan, Chun-Yu Shei, and Pushkar Ratnalikar Indiana University, Bloomington, IN 47405, USA fakeep,achauhan,cshei,[email protected] Abstract. We introduce a Domain Specific Language (DSL), called RubyWrite, embedded within Ruby, with the goal of providing an ex- tensible, effective, portable, and easy to use framework for encoding source-level transformations. Embedding within Ruby provides access to the powerful features of Ruby, including its purely object-oriented design and meta-programming capabilities. The syntactic flexibility and advanced language features of Ruby drove our choice of it as the host lan- guage. Easy integration of external C interfaces seamlessly within Ruby lets us move performance critical operations to C, or link with external libraries. RubyWrite was developed to aid our compiler research where it provides the core of three compiler infrastructure development projects, and is used as a teaching aid in a graduate-level compilers course. We expect RubyWrite to be widely applicable and a proof of concept in leveraging an existing modern language to write a portable compiler in- frastructure core. 1 Introduction We describe a Domain Specific Language (DSL), embedded within Ruby, aimed at simplifying the task of source-level transformations through term-rewriting. The DSL, called RubyWrite, is motivated by the need for a compiler development environment that allows easy integration of source-level transformations with program analysis. After spending frustrating months trying to develop a compiler for matlab in C++ a few years ago, we made the decision to move to a domain-specific lan- guage for compiler development.
    [Show full text]