# LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.

Size: px
Start display at page:

Download "LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits."

Transcription

1 LISP Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits, but from another perspective, sequences of bits can be interpreted as a code for real world like objects and sentences like objects. In LISP, the fundamental things formed from bits are world like objects called atoms. Groups of atoms form sentence like objects called lists. Lists themselves can be grouped together to form higher-level lists. Atoms and lists collectively are called symbolic expressions, or expressions. Working with symbolic expressions is what symbol manipulation using LISP about. Basic LISP Primitives. In LISP, the prompt is an asterisk: *. The words beyond the semicolon are comments inserted for explanation-a semicolon makes the remainder of the words on a line invisible to LISP. Suppose for example, that we want some help adding numbers. The proper way of doing is, once LISP displayed the prompt, is as follows *( ) LISP responds as follows: 5.85 This is a simple example of LISP s ability to handle arithmetic. When left and right parentheses 1

2 surround something, we call the result a list and speak of its elements. In our first example, the list ( ) has three elements, +, 3.14, and 2.71, separated by spaces. + is standing before the two things to be added, rather than between them, as in ordinary arithmetic notation. In LISP the name of the thing to do, the procedure, is always specified first, followed then by the things that the procedure is to work with, the arguments. FIRST and REST take lists apart. For example *(first (fast computers are nice)) FAST *(rest (fast computers are nice)) COMPUTERS ARE NICE Also, when REST is applied to a list with only one element, it returns the empty list, which we can denote by either () or NIL. *(rest (nice)) NIL To assign values to symbols is to use SETF. This primitive causes the value of its second argument to be assigned to its first argument. Consider this: *(setf ab-list (a b)) When we type : *ab-list (A B) While FIRST and REST take things apart, CONS, APPEND, and LIST. CONS takes expression 2

3 and a list and returns a new list whose first element is the expression and whose remaining elements are those of the old list: *(cons a (b c)) This will display : A B C. The template for cons is (cons <new first element> <a list>). APPEND combines the elements of all lists supplied as arguments. For example: *(setf ab-list (a b) xy-list (x y)) *(append ab-list xy-list) (A B X Y) A LIST makes a list out of its arguments. Each argument becomes an element of the new list: *(setf front a middle b back c) *(list front middle back) (A B C) NTHCDR trims off n elements, not just one, with the first argument determining the exact number: *(setf abc-list (a b d)) *(nthcdr 2 abc-list) (D) BUTLAST is similar to NTHCDR, but trims off the last n elements, rather than the first. *(setf abc-list (a b d)) 3

4 *(butlast abc-list 2) (A) LAST returns a list with all but the last element of a list trimmed off: *(setf abc-list (a b d) ab-cd-list ((a b) (d e))) *(last abc-list) (D) The LENGTH primitive counts the number of top-level elements in a list. REVERSE reverses the order of the top-level elements of a list. *(setf ab-list (a b) ) *(length ab-list) 2 *(reverse ab-list) (B A) The ASSOC primitive is especially tailored to work with a particular kind of association-recording expression called an association list. The first element of each sublist is used as a key for recovering the entire sublist. *(setf sarah ((height.54) (weight 4.4))) *(assoc weight sarah) (WEIGHT 4.4) 4

5 LISP also has other very important mathematical functions. Round function rounds the number to the nearest integer. *(round (/22 7)) 3 :The nearest integer 1/7 : The remainder MAX and MIN find maxima and minima. EXPT calculates powers; it raises its first argument to its second. SQRT takes the square root, and finally ABS computes the absolute value. *(MAX 2 4 3) 4 *(MIN 2 4 3) 2 *(expt 2 3) 8 *(sqrt 9) 3 *(abs -5) 5 Procedure Definition and Binding DEFUN is LISP s Procedure-Definition Primitive For example: 5

6 *(setf whole-list (breakfast lunch tea dinner)) (defun both-ends (whole -list) (cons (first whole-list) (last whole-list) LET forms bind parameters to initial value. *(setf whole-list (breakfast lunch tea dinner)) *(let ((element (first whole-list)) (trailer (last whole-list)) (cons element trailer)) Bind ELEMENT to initial value. Bind TRAILER to initial value. Combine ELEMENT and TRAILER. This will display BREAKFAST DINNER. Predicates and Conditionals A predicate is a procedure that returns true or false. For example : *(equal (+2 2) 4) T *(equal(+2 3) 3) NIL Several predicates determine if their arguments are equal. They range from EQUAL, which is a general purpose predicate, but computationally expensive, to EQL, EQ and =. MEMBER Tests for List Membership. The MEMBER predicate tests to see if its first argument is 6

7 an element of its second argument. MEMBER returns what is left of the list when the matching symbol is encountered. *(setf sentence (tell me more about your mother please)) *(member mother sentence) (MOTHER PLEASE) LISP has many predicates that test objects to see whether they belong to a particular data type. Name Purpose atom Is it an atom? numberp Is it a number? symbolp Is it a symbol? listp Is it a list? null Is the argument an empty list? endp Is the argument, which must be a list, an empty list? zerop Is it zero? plusp Is it positive? minusp Is it negative? 7

8 evenp Is it even? oddp Is it odd? > Are they in descending order? < Are they in ascending order? Predicates help IF, WHEN, and UNLESS Choose among Alternatives. *(if (sumbolp day-or-date) day date) The result is the symbol DAY if the value of day-or-date is a symbol, and DATE otherwise. A WHEN can be used instead of an IF whenever the false consequent in an equivalent IF form would be NIL. An UNLESS can be used instead of an IF whenever the then form in an equivalent IF form would be NIL. Predicates also help COND choose among alternatives. COND is particularly useful when there are more than two cases to consider. In the following example, a probability number between 0 and 1 is converted into one of four symbols: *(setf p.6) *(cond ((>p.75) very-likely) ((>p.5) likely) ((>p.25) unlikely) (t very-unlikely)) LIKELY CASE checks the evaluated key form against the unevaluated keys using EQL. If the key is found, the corresponding clause is triggered and all of the clause s corresponding clause is triggered and 8

9 all of the clause s consequents are evaluated. *(setf thing ball r1) *(case thing ((circle wheel) (*pi r r)) ((sphere ball) (*4 pi r r)) (Otherwise 0)) Procedure Abstraction and Recursion Procedure Abstraction Hides Details Behind Abstraction Boundaries. For Example: *(setf l (breakfast lunch tea dinner)) *(both-ends l) (BREAKFAST DINNER) To do its job, both-ends must do three things: BOTH-ENDS must extract the first element. It must extract the last element. It must combine the two extracted elements. Recursion allows procedures to use themselves. To calculate the nth power of some number, m,it is sufficient to do the job for the (n-1)th power, because this result, multiplied by m, is the desired result for the nth power: (defun higher-level-expt (m n) (if (zerop n) 9

10 1 If n=0, return 1. (* m Otherwise, use a higher-level abstraction (higher-level-expt m(-n 1))))) Data Abstraction We can hide the details of how our data is represented by isolating that data behind a set of constructor procedures that create data, reader procedures that retrieve data, and writer procedures that change data. For example BOOK-AUTHOR is the reader procedure for retrieving a book s author. When we start out, BOOK-AUTHOR is defined as follows (defun book-author (book) ;Data is in a simple list. (second book)) And here is an example of BOOK-AUTHOR in use (setf book-example1 ((Artificial Intelligence) (Patrick Henry Winston) (Technical AI))) ;Title ;Author ;Index terms. *(book-author book-example-1) (PATRICK HENRY WINSTON) And this is how Constructor works (defun make-book (title author classification) (list (list title title) 10

11 (list author author) (list classification classification))) The constructor creates a new book, given appropriate arguments. * (setf book-example-4 (make-book (Common Lisp) (Guy Steele) (Technical Lisp))) (TITLE (COMMON LISP)) (AUTHOR (GUY STEELE)) (CLASSIFICATION (TECHNICAL LISP))) Loops The DOTIMES primitive is popular because it provides a way to write simple counting-oriented iteration procedures. (defun dotimes-expt (m n) (let ((result 1)) (dotimes (count n result) (setf result (*m result))))) ;Initialize result parameter. ;Evaluate body n times ;Multiply by m again The DOLIST primitive is similar to DOTIMES except that the elements of a list are assigned, one after another, to the parameter. This is the general template. (dolist (<element parameter> <list form> <result form>) <body>) 11

12 The DO primitive can be used for iteration when DOLIST and DOTIMES are just not flexible enough. Otherwise, we should avoid DO because it is harder to use. (defun do-expt (m n) (do ((result 1) (exponent n)) ((zerop exponent) result) (setf result (* m result)) (setf exponent (- exponent 1)))) ;Bind parameters ;Bind parameters ;Test and return ;Body ;Body Printing and Reading For example *(setf temperature 100) *(print temperature) 100 When the primitive READ is encountered, LISP stops and waits for us to type an expression. FORMAT formats the line while it is printing. For example *(format t ~%Hello! ) Hello! ;FORMAT prints Hello! NIL READ does not Evaluate Expressions, but EVAL evaluates twice String manipulation is done by special primitives: 12

13 length gives length of the string reverse reverses the string elt If the first argument in an elt form is an list, then elt returns the element specified by the second argument, where 0 specifies the first element. string= To determine if two strings are the same(case sensitive) string-equal To determine if two strings are the same (is not case sensitive) char= To determine if two characters are the same (case sensitive) char=equal To determine if two characters are the same (is not case sensitive) search To determine if one string is contained in another. read-line, read-char Useful for reading strings and characters from a terminal or file Properties, Methods, Structures,Classes Get and Setf are the primitives that we use when we want to retrieve information of a property, or assign to a value to the property. Methods are procedures selected from generic functions by argument types. (defmethod area ((figure rectangle) (*(rectangle-width figure) (Rectangle-height figure))) ;Method for rectangles 13

14 User defined structure types facilitate data abstraction. Here is how they are used: (defstruct person (sex nil) (personality nice)) ;Default value is NIL ;Default value is NICE Here is what is done by DEFSTRUCT forms: Creates a constructor procedure Creates reader procedures for getting things out of an instance s fields. Generalizes setf, to serve a writer when used in combination with the readers Creates a predicate for testing objects to see if they are instances of the DEFSTRUCT defined data type Classes are usually arranged in hierarchies. When we can reach one class by walking up a series of connections, the lower class is called a subclass of the upper one, and the upper one is called a superclass of the lower one. The connections are called inheritance links because each class inherits slots from its superclasses. Encapsulation Lambda is used when mapping is done. Lambda defines anonymous procedures. Encapsulation enables the creation of sophisticated generators. The sophisticated way to create generators is to encapsulate free variables in lambda definitions by embedding the lambda definition in a parameter-containing form. Reference: LISP 3 rd Edition Patrick Henry Winston and Berthold Klaus Paul Horn 14

15 15

### Lecture Notes on Lisp A Brief Introduction

Why Lisp? Lecture Notes on Lisp A Brief Introduction Because it s the most widely used AI programming language Because Prof Peng likes using it Because it s good for writing production software (Graham

### Modern Programming Languages. Lecture LISP Programming Language An Introduction

Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation

### Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the

### Imperative, OO and Functional Languages A C program is

Imperative, OO and Functional Languages A C program is a web of assignment statements, interconnected by control constructs which describe the time sequence in which they are to be executed. In Java programming,

### Functional programming with Common Lisp

Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions

### Common Lisp. Blake McBride

Contents Common Lisp Blake McBride (blake@mcbride.name) 1 Data Types 2 2 Numeric Hierarchy 3 3 Comments 3 4 List Operations 4 5 Evaluation and Quotes 5 6 String Operations 5 7 Predicates 6 8 Math Predicates

### CS 480. Lisp J. Kosecka George Mason University. Lisp Slides

CS 480 Lisp J. Kosecka George Mason University Lisp Slides Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic

### Object oriented programming

Object oriented programming The main ideas behind object-oriented programming: the same type of action may be carried out differently on different types of objects cutting a cake is different from cutting

### INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. More Common Lisp

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing More Common Lisp Stephan Oepen & Murhaf Fares Language Technology Group (LTG) September 6, 2017 Agenda 2 Previously Common

### FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE,

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti L I S P - Introduction L I S P

### Department of Computer and information Science Norwegian University of Science and Technology

Department of Computer and information Science Norwegian University of Science and Technology http://www.idi.ntnu.no/ A Crash Course in LISP MNFIT272 2002 Anders Kofod-Petersen anderpe@idi.ntnu.no Introduction

### Common LISP-Introduction

Common LISP-Introduction 1. The primary data structure in LISP is called the s-expression (symbolic expression). There are two basic types of s-expressions: atoms and lists. 2. The LISP language is normally

### Announcement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp.

Overview Announcement Announcement Lisp Basics CMUCL to be available on sun.cs. You may use GNU Common List (GCL http://www.gnu.org/software/gcl/ which is available on most Linux platforms. There is also

### A little bit of Lisp

B.Y. Choueiry 1 Instructor s notes #3 A little bit of Lisp Introduction to Artificial Intelligence CSCE 476-876, Fall 2017 www.cse.unl.edu/~choueiry/f17-476-876 Read LWH: Chapters 1, 2, 3, and 4. Every

### Scheme Quick Reference

Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries

### 15 Unification and Embedded Languages in Lisp

15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed

### CSCI337 Organisation of Programming Languages LISP

Organisation of Programming Languages LISP Getting Started Starting Common Lisp \$ clisp i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8 8 8 ooooo

### Scheme Quick Reference

Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete

### Chapter 1. Fundamentals of Higher Order Programming

Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme

### Functions, Conditionals & Predicates

Functions, Conditionals & Predicates York University Department of Computer Science and Engineering 1 Overview Functions as lambda terms Defining functions Variables (bound vs. free, local vs. global)

### Artificial Intelligence Programming

Artificial Intelligence Programming Rob St. Amant Department of Computer Science North Carolina State University Lisp basics NC State University 2 / 99 Why Lisp? Some recent Lisp success stories include

### 6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

### Lisp Basic Example Test Questions

2009 November 30 Lisp Basic Example Test Questions 1. Assume the following forms have been typed into the interpreter and evaluated in the given sequence. ( defun a ( y ) ( reverse y ) ) ( setq a (1 2

### INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing Common Lisp Fundamentals Stephan Oepen & Murhaf Fares Language Technology Group (LTG) August 30, 2017 Last Week: What is

### 11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the

### Robot Programming with Lisp

2. Imperative Programming Institute for Artificial University of Bremen Lisp the Language LISP LISt Processing language 2 Lisp the Language LISP LISt Processing language (LISP Lots of Irritating Superfluous

### Common Lisp Object System Specification. 1. Programmer Interface Concepts

Common Lisp Object System Specification 1. Programmer Interface Concepts Authors: Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Draft Dated:

### Allegro CL Certification Program

Allegro CL Certification Program Lisp Programming Series Level I Review David Margolies 1 Summary 1 A lisp session contains a large number of objects which is typically increased by user-created lisp objects

### 6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

### Debugging in LISP. trace causes a trace to be printed for a function when it is called

trace causes a trace to be printed for a function when it is called ;;; a function that works like reverse (defun rev (list) (cons (first (last list)) (rev (butlast list)))) USER: (trace rev) ; note trace

### Lambda Calculus and Lambda notation in Lisp II. Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky.

λ Calculus Basis Lambda Calculus and Lambda notation in Lisp II Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky Mathematical theory for anonymous functions» functions that have

### Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### Recursion & Iteration

Recursion & Iteration York University Department of Computer Science and Engineering 1 Overview Recursion Examples Iteration Examples Iteration vs. Recursion Example [ref.: Chap 5,6 Wilensky] 2 Recursion

### Lisp. Versions of LISP

Lisp Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks is based on Common Lisp Scheme is one of the major

### SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### Introduction to Functional Programming

Introduction to Functional Programming Xiao Jia xjia@cs.sjtu.edu.cn Summer 2013 Scheme Appeared in 1975 Designed by Guy L. Steele Gerald Jay Sussman Influenced by Lisp, ALGOL Influenced Common Lisp, Haskell,

### Documentation for LISP in BASIC

Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have

### Chapter 15 Functional Programming Languages

Chapter 15 Functional Programming Languages Fundamentals of Functional Programming Languages Introduction to Scheme A programming paradigm treats computation as the evaluation of mathematical functions.

### CIS4/681 { Articial Intelligence 2 > (insert-sort '( )) ( ) 2 More Complicated Recursion So far everything we have dened requires

1 A couple of Functions 1 Let's take another example of a simple lisp function { one that does insertion sort. Let us assume that this sort function takes as input a list of numbers and sorts them in ascending

### CSC 533: Programming Languages. Spring 2015

CSC 533: Programming Languages Spring 2015 Functional programming LISP & Scheme S-expressions: atoms, lists functional expressions, evaluation, define primitive functions: arithmetic, predicate, symbolic,

### Functional programming in LISP

Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University review of part 3 enumeration of dictionaries you receive a sequence of

### Homework 1. Reading. Problems. Handout 3 CSCI 334: Spring, 2012

Homework 1 Due 14 February Handout 3 CSCI 334: Spring, 2012 Reading 1. (Required) Mitchell, Chapter 3. 2. (As Needed) The Lisp Tutorial from the Links web page, as needed for the programming questions.

### Notes on Higher Order Programming in Scheme. by Alexander Stepanov

by Alexander Stepanov August 1986 INTRODUCTION Why Scheme? Because it allows us to deal with: 1. Data Abstraction - it allows us to implement ADT (abstact data types) in a very special way. The issue of

### CSCE476/876 Fall Homework 3: Programming Assignment Using Emacs and Common Lisp. 1 Exercises (15 Points) 2. 2 Find (6 points) 4

CSCE476/876 Fall 2018 Homework 3: Programming Assignment Using Emacs and Common Lisp Assigned on: Monday, September 10 th, 2018. Due: Monday, September 24 th, 2018. Contents 1 Eercises (15 Points) 2 2

Announcements 1 Today s Menu Finish Introduction to ANNs (original material by Dr. Mike Nechyba) > Slides 58-60 > Adjusting the Learning Rate Loose Ends in > Lambda Expressions Review > I/O Functions >

### SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### Functional Programming. Big Picture. Design of Programming Languages

Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

### FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 3. LISP: ZÁKLADNÍ FUNKCE, POUŽÍVÁNÍ REKURZE,

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 3. LISP: ZÁKLADNÍ FUNKCE, POUŽÍVÁNÍ REKURZE, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti Comments in Lisp ; comments

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 3: Scheme Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1]

### Lisp as a Second Language Chapter 1 Functional Style

1 of 61 05/07/2018, 11:35 [an error occurred while processing this directive] Lisp as a Second Language Chapter 1 Functional Style Draft mars 11, 1997 1. Lists as the main data structure 2. Abstraction

### Functional Programming Languages (FPL)

Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

### Object Oriented Programming (OOP)

Object Oriented Programming (OOP) o New programming paradigm o Actions Objects o Objects Actions o Object-oriented = Objects + Classes + Inheritance Imperative programming o OOP (Object-Oriented Programming)

### (defvar *state* nil "The current state: a list of conditions.")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; GPS engine for blocks world ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar *dbg-ids* nil "Identifiers used by dbg") (defvar *state* nil "The current state: a list of conditions.")

### CS A331 Programming Language Concepts

CS A331 Programming Language Concepts Lecture 10 Alternative Programming Languages (Functional LISP Declarative - PROLOG) March 24, 2014 Sam Siewert Functional PL Concepts Based on Lambda Calculus Output

### 1.3. Conditional expressions To express case distinctions like

Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

### SCHEME AND CALCULATOR 5b

SCHEME AND CALCULATOR 5b COMPUTER SCIENCE 6A July 25, 203 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### Functional Programming. Pure Functional Languages

Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

### ;; definition of function, fun, that adds 7 to the input (define fun (lambda (x) (+ x 7)))

Homework 1 Due 13 September Handout 2 CSC 131: Fall, 2006 6 September Reading 1. Read Mitchell, Chapter 3. 2. The Scheme Tutorial and the Scheme Quick Reference from the Links web page, as needed for the

### CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.

### A Genetic Algorithm Implementation

A Genetic Algorithm Implementation Roy M. Turner (rturner@maine.edu) Spring 2017 Contents 1 Introduction 3 2 Header information 3 3 Class definitions 3 3.1 Individual..........................................

### Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu

### 19 Machine Learning in Lisp

19 Machine Learning in Lisp Chapter Objectives Chapter Contents ID3 algorithm and inducing decision trees from lists of examples. A basic Lisp implementation of ID3 Demonstration on a simple credit assessment

### Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

### Introduction to Artificial Intelligence CISC-481/681 Program 1: Simple Lisp Programs

CISC-481/681 Program 1: Simple Lisp Programs 1 Introduction to Artificial Intelligence CISC-481/681 Program 1: Simple Lisp Programs Reading: Handouts Summarizing Common Lisp Functions Paul Graham s ANSI

### Functional Programming. Pure Functional Languages

Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

### Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

### Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

### Allegro CL Certification Program

Allegro CL Certification Program Lisp Programming Series Level I Presented by 1 About David Margolies Manager, Documentation, Franz Inc Been working with Lisp since 1984 dm@franz.com 2 About Franz Inc.

### Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

Homework 1 Due 14 February Handout 3 CSCI 334: Spring, 2017 Notes This homework has three types of problems: Self Check: You are strongly encouraged to think about and work through these questions, but

### A Quick Introduction to Common Lisp

CSC 244/444 Notes last updated ug. 30, 2016 Quick Introduction to Common Lisp Lisp is a functional language well-suited to symbolic I, based on the λ-calculus and with list structures as a very flexible

### Fifth Generation CS 4100 LISP. What do we need? Example LISP Program 11/13/13. Chapter 9: List Processing: LISP. Central Idea: Function Application

Fifth Generation CS 4100 LISP From Principles of Programming Languages: Design, Evaluation, and Implementation (Third Edition, by Bruce J. MacLennan, Chapters 9, 10, 11, and based on slides by Istvan Jonyer

### Functional Programming. Pure Functional Programming

Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

### Introduction to Functional Programming and basic Lisp

Introduction to Functional Programming and basic Lisp Based on Slides by Yves Lespérance & Peter Roosen-Runge 1 Functional vs Declarative Programming declarative programming uses logical statements to

### FP Foundations, Scheme

FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming -- Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages

### ALISP interpreter in Awk

ALISP interpreter in Awk Roger Rohrbach 1592 Union St., #94 San Francisco, CA 94123 January 3, 1989 ABSTRACT This note describes a simple interpreter for the LISP programming language, written in awk.

### UMBC CMSC 331 Final Exam

UMBC CMSC 331 Final Exam Name: UMBC Username: You have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for answers that are needlessly wordy

### CPS 506 Comparative Programming Languages. Programming Language Paradigm

CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming

### (defun fill-nodes (nodes texts name) (mapcar #'fill-node (replicate-nodes nodes (length texts) name) texts))

PROBLEM NOTES Critical to the problem is noticing the following: You can t always replicate just the second node passed to fill-nodes. The node to be replicated must have a common parent with the node

### Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is

### 6.001: Structure and Interpretation of Computer Programs

6.001: Structure and Interpretation of Computer Programs Symbols Quotation Relevant details of the reader Example of using symbols Alists Differentiation Data Types in Lisp/Scheme Conventional Numbers

### A Small Interpreted Language

A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that

1 of 5 5/11/2006 12:10 AM CS 61A Spring 2006 Midterm 2 solutions 1. Box and pointer. Note: Please draw actual boxes, as in the book and the lectures, not XX and X/ as in these ASCII-art solutions. Also,

### SCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012

SCHEME COMPUTER SCIENCE 6A October 29th, 202 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs, we will eventually

### An introduction to Scheme

An introduction to Scheme Introduction A powerful programming language is more than just a means for instructing a computer to perform tasks. The language also serves as a framework within which we organize

### Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme

### Lisp: Question 1. Dr. Zoran Duric () Midterm Review 1 1/ 13 September 23, / 13

Lisp: Question 1 Write a recursive lisp function that takes a list as an argument and returns the number of atoms on any level of the list. For instance, list (A B (C D E) ()) contains six atoms (A, B,

### Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.

6.001, Fall Semester, 2002 Quiz II Sample solutions 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs

### Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions

### The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about

Lesson 0.4 Introduction to Racket Preliminaries The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about Expressions Numbers, Booleans, and

### Putting the fun in functional programming

CM20167 Topic 4: Map, Lambda, Filter Guy McCusker 1W2.1 Outline 1 Introduction to higher-order functions 2 Map 3 Lambda 4 Filter Guy McCusker (1W2.1 CM20167 Topic 4 2 / 42 Putting the fun in functional

### Scheme Basics > (butfirst '(help!)) ()

Scheme Basics > (butfirst '(help!)) () [The butfirst of a *sentence* containing one word is all but that word, i.e., the empty sentence. (BUTFIRST 'HELP!) without the inner parentheses would be butfirst

### Why do we need an interpreter? SICP Interpretation part 1. Role of each part of the interpreter. 1. Arithmetic calculator.

.00 SICP Interpretation part Parts of an interpreter Arithmetic calculator Names Conditionals and if Store procedures in the environment Environment as explicit parameter Defining new procedures Why do

### Functional Programming. Contents

Functional Programming Gunnar Gotshalks 2003 September 27 Contents Introduction... 2 Example for Inner Product... 2 Basis Set for Functionals... 3 Example Function Definitions... 3 Lisp Builtin Functionals...

### LECTURE 16. Functional Programming

LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

### Lecture #24: Programming Languages and Programs

Lecture #24: Programming Languages and Programs A programming language is a notation for describing computations or processes. These range from low-level notations, such as machine language or simple hardware

### Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type