Announcements. Today s Menu

Size: px
Start display at page:

Download "Announcements. Today s Menu"

Transcription

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

2 Finish Anns See Class 11 Notes Slides ANN Example 3 LAMBDA Expressions allow us to define anonymous procedures The lambda expression is the actual mechanism that the interpreter uses to "evaluate" dummy arguments in a procedure. This is what X returns when you use FUNCTION- LAMBDA-EXPRESSION. Suppose we want to put quotes around all the elements of an input list. (defun put-quotes(lis) (mapcar #'qhelp lis)) (defun qhelp(sex) (list (quote quote) sex)) > (put-quotes '(this is a test)) ((QUOTE THIS) (QUOTE IS) (QUOTE A) (QUOTE TEST)) But if you begin to run out of names for your "helper" functions (especially if they are only used once in a program) a more elegant solution is given by: (defun put-quotes(lis) (mapcar #'(lambda(sex) (list (quote quote) sex)) lis )) 4

3 Lambda Expressions The actual mechanism that runs user-defined functions is the built-in lambda expression. For example, let us define a function to increment, say, inc. >(defun inc(x) (+ 1 x)) INC >(inc 1) 2 >(function-lambda-expression #'inc) (lambda(x) (+ 1 x)) What is stored in the system when you use function inc is the symbolic expression (lambda(x) (+ 1 x)). That is, inc and (lambda(x) (+ 1 x)) are one in the same. To prove it, replace inc with (lambda(x) (+ 1 x)) in the expression (inc 1). > ((lambda(x) (+ 1 x)) 1) 2 5 Lambda Expressions Lambda expressions can be used as anonymous functions anywhere you would otherwise use a named function. For example, using inc we can increment a list of integers using the built-in function mapcar. The syntax for mapcar is (mapcar function-f list-of-arguments-for-f ). The result is (list (f (first of list)) (f (second of list)) (f (third of list)) etc.) > (mapcar # oddp '(1 2 3)) (t nil t) > (mapcar #'inc '(1 2 3)) (2 3 4) > (mapcar #'(lambda(x) (+ 1 x)) '(1 2 3)) (2 3 4) This example shows that we did not need to do a defun to define inc and could just use the code for inc (its corresponding lambda expression) in the same manner as we used inc. This is more efficient because we save the space and OH of having to define the function inc in order to use it inside mapcar. 6

4 Lambda Expressions In some cases, to solve scoping problems we must use the lambda (anonymous function) instead of defun. For example, to do the intersection of two sets we need a helper function that checks to see if each element of s1 is in s2. If yes, it belongs in the intersection, if not, we do not keep it. Let me call the helper function finter. finter returns the element from s1 that is also inside s2 as a list or returns nil. > (defun inter(s1 s2) (mapcan # finter s1)) > (defun finter (sex) (cond ( (member sex s2) (list sex)) ( t nil) )) For example if s1 is (a b) and s2 is (a c), (finter a) would return (a) and (finter b) would return (). If I append these two answers, presto, I get the result of (inter (a b) (a c)) = (a) 7 Lambda Expressions But there is a problem. What is the s2 inside finter? You could say that s2 is global to finter. Using that line of reasoning we could write (inter s1 s2) as follows: > (defun inter(s1 s2) (mapcan # finter s1)) > (inter (a b) (a c)) ***ERROR*** What is the problem? When you call finter inside inter, s2 is known to inter but not to finter. The scope of s2 is inside the definition of inter and it is not made global to. But as we said earlier the s2 in finter is global to finter. The interpreter cannot resolve this problem. But if you use the anonymous version of finter inside inter, all is well. > (defun inter(s1 s2) (mapcan #'(lambda (sex) (cond ( (member sex s2) (list sex)) ( t nil) )) s1)) > (inter (a b) (a c)) (A) 8

5 General MAPing Functions MAPCAR and related mapping functions allow us to easily transform lists. MAPCAR takes two arguments, the first is a funarg and the second a list. The answer is a list of the results of applying the functional argument to each successive car of the 2 nd argument. Thus, (mapcar #'f '(x 1 x 2 x 3 )) ==> (list f(x 1 ) f(x 2 ) f(x 3 )) template: (mapcar #'<fname> <a list of SEXes for fname>) > (mapcar # oddp '(1 2 3)) ==> (T NIL T) We can define mapcar as follows: (defun mymapcar (f lis) (cond ( (null lis) nil ) ( t (cons (funcall f (car lis)) (mymapcar f (cdr lis))) ) )) > (mymapcar #'oddp '(1 2 3)) ==> (T NIL T) 9 User-Defined MAPing Functions Using our definition of MAPCAR we can define MAPPENDCAR, (MAPCAN) which applies f (.) to successive cdrs as follows: (defun mappendcar (f lis) (cond ( (null lis) nil ) ( t (append (funcall f (car lis)) (mappendcar f (cdr lis))) ) )) (defun inter (s1 s2) (mappendcar #'ihelp s1)) (defun ihelp (s1el) (cond ( (member s1el s2) (list s1el)) ( t nil) )) But this will not work either. Why? (Same as in Slide 7} 10

6 > (inter '(a b) '(b c)) Error: The variable S2 is unbound. Happened in: #<Closure-IHELP: #76dc8c The reason is obvious(?), s2 is only defined inside INTER but is undefined inside ihelp. We MUST use lambda: > (defun inter (s1 s2) (mappendcar #'(lambda (s1el) (cond ( (member s1el s2) (list s1el)) ( t nil))) s1)) INTER > (inter '(a b) '(b c)) (B) 11 MAPing Functions Example Use a mapping function to transpose an N N matrix represented as N lists of N integers each, e.g., Lisp (setf mat '((1 2 3) (4 5 6) (7 8 9))) ( (1 2 3) (4 5 6) (7 8 9) ) Lisp (transpose mat ) ( (1 4 7) (2 5 8) (3 6 9) ) Lisp (transpose '( (1 2) (3 4) (5 6) ) ) ( (1 3 5) (2 4 6) ) > (mapcar #'car mat) (1 4 7) > (mapcar #'cdr mat) ( (2 3) (5 6) (8 9) ) Lisp (defun transp (mat) (if (null (car mat)) nil (cons (mapcar #'car mat) (transp (mapcar #'cdr mat))))) Lisp (transp mat) ( (1 4 7) (2 5 8) (3 6 9) ) 12

7 Substop replaces a sex in a list at the top-level. (defun substop (this that lis) (cond ((null lis) nil) ((equal that (car lis)) (cons this (substop this that (cdr lis)))) ('else (cons (car lis) (substop this that (cdr lis)))) )) Let s try to write substop using a mapping function. (defun replacesex (sex3) (if (equal sex1 sex3) sex2 sex3)) /* sex1,2 are global! */ (defun substop (sex1 sex2 lis) (mapcar #'replacesex lis)) /* The following code will not run. Why? */ > (substop 'coke 'pepsi '(coke is it)) Error: The variable SEX1 is unbound. Happened in: #<Closure-REPLACESEX: #794b20> A Lambda Expression let us fix this nicely > (defun substop (sex1 sex2 lis) (mapcar #'(lambda (sex3) (if (equal sex1 sex3) sex2 sex3)) lis)) > (substop 'coke 'pepsi '(coke is it)) (PEPSI IS IT) 13 I/O I/O Functions in The following represents a sampling of the available I/O functions in. For a complete list see the Reference Manual. If the file pointers outf or inf are omitted, the system defaults to the terminal. (setf outf (open "fname" :direction :output)) Opens disk file fname for output. Sets outf, i.e., a file pointer for further use. (print Sex outf) Returns the value of the Sex and sends a copy to outf. (dribble "fname") Echoes all CRT I/O to the disk file (prin1 Sex outf) Same as print except for the trailing cr/lf (terpri outf) Issues a cr/lf (read inf) Inputs the next Sex from inf (or CRT if inf omitted) (read-line inf) Read 1 line from inf (read-char inf) Read 1 character from inf (close outf) Close file outf (or inf) 14

8 PROG The PROG construct allows for an indefinite number of forms to be evaluated with local variables. In modern it has been replaced by LET and LOOP constructs, but it is still useful. (prog (var1 var2... varn) <forms>) 1. The number of forms in prog is indeterminate. 2. PROG initializes all its local variables to nil (var1 var2... varn). 3. <Forms> are evaluated in order except: a. Atomic forms are not evaluated. They are treated as labels. b. (GO label) means continue from the form that follows label. c. (return expr) exits a prog evaluation & returns (eval expr). 4. If a prog runs out of forms, it returns nil. 5. If a cond runs out of stuff inside a prog it is treated as a NOOP. 15 Example: (defun fact (n) (prog (i j) (if (< n 0) (return nil) ) (setf i 1 j 1) ( if (< n 2) (return j) ) LOOP (setf i (+ i 1) j (* j i) ) (if (= i n) (return j)) (go LOOP) )) 16

9 LOOPING Common includes most(all) the most popular looping constructs template: (dotimes (<count atm> <upperbound form> <result form>) <body>) > (defun power (m n) (let ((result 1)) ( dotimes (count n result) (setf result (* m result)) ) )) Also template: (dolist (<element> <list form> <result form>) <body>) > (dolist (n '(1 2 3) 'end) (prin1 (list 'n= n 'n+1= (+ 1 n))) (prin1 '!)) (N= 1 N+1= 2)!(N= 2 N+1= 3)!(N= 3 N+1= 4)!END > (let ((n 0))(dolist (grade '((john a) (mary b) (james c) (dick a)) (list n 'non-agrades)) (if (equal (cadr grade) 'a) (print (list 'a (car grade))) (setf n (+ 1 n))) ) ) * Prints all the A grades in the input list & counts the non-a grades * EVALUATIONS (eval sex) hands sex to the interpreter if (setf x '(+ 1 2) ) then (eval x) returns 3 17 PROPERTY LISTS {Review} The ability to associate with an atom in a lisp form (pvalue, the property value) under a given atomic designation (pname, the property name). template: (putprop symb pvalue pname) {Requires 3 arguments} symb - must be atomic, i.e., the atom to receive the property. pvalue - the property value, which can be any sex. pname - must also be atomic, i.e., the property name. > (putprop 'cain 'adam 'father) ADAM > (putprop 'eve '(cain abel) 'mother-of ) (CAIN ABEL) > (setf eve 'first-woman) FIRST-WOMAN > eve FIRST-WOMAN 18

10 Putprop is not always included in some dialects. If not use: > (setf (get 'cain 'father) 'adam) > (setf (get 'eve 'mother-of) '(cain abel)) > (setf (get 'eve 'grandmother) '(tubalcain jubal)) (defun putprop (atm pvalue pname) (setf (get atm pname) pvalue)) In memory, property lists are stored as association lists or dotted pairs associated with the atom, e.g., ( eve (mother (cain abel)) (grandmother (tubalcain jubal)) ) 19 To retrieve properties use the function (get atm pname). It returns the property value if one has been defined or nil. Therefore, the system cannot distinguish between undefined properties and those whose value has been set to nil. A good rule to follow is to always set pvalue to something non-nil > (get 'cain 'father) ADAM > (get 'eve 'mother-of) (CAIN ABEL) > (get 'cain 'grandfather) NIL To remove a property use (remprop symb pname). Returns nil. > (remprop 'cain 'father) NIL > (get 'cain 'father) NIL 20

11 Another way to view this is as an associated list of pairs (a-list for short). Associated pairs are lists of sublists where the first element of each sublist is a "key or indicator" and the cdr of the sublist is the value. For example: > (setq eve '( (mother (cain abel)) (grandmother (tubalcain jubal)) )) ((MOTHER (CAIN ABEL)) (GRANDMOTHER (TUBALCAIN JUBAL))) > eve ((MOTHER (CAIN ABEL)) (GRANDMOTHER (TUBALCAIN JUBAL))) The function (assoc key a-list) returns the corresponding pair that has a key value matching argument. > (assoc 'mother eve) (MOTHER (CAIN ABEL)) (defun myassoc (key alist) (cond ( (null alist) nil ) ( (equal key (caar alist)) (car alist) ) ( t (myassoc key (cdr alist)) ) )) 21 The End! 22

Lisp Basic Example Test Questions

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

More information

Modern Programming Languages. Lecture LISP Programming Language An Introduction

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

More information

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

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

More information

FP Foundations, Scheme

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

More information

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

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

More information

Common Lisp. Blake McBride

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

More information

Lecture Notes on Lisp A Brief Introduction

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

More information

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY,

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY, FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší

More information

Common LISP-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

More information

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

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

More information

INF4820. Common Lisp: Closures and Macros

INF4820. Common Lisp: Closures and Macros INF4820 Common Lisp: Closures and Macros Erik Velldal University of Oslo Oct. 19, 2010 Erik Velldal INF4820 1 / 22 Topics for Today More Common Lisp A quick reminder: Scope, binding and shadowing Closures

More information

Common LISP Tutorial 1 (Basic)

Common LISP Tutorial 1 (Basic) Common LISP Tutorial 1 (Basic) CLISP Download https://sourceforge.net/projects/clisp/ IPPL Course Materials (UST sir only) Download https://silp.iiita.ac.in/wordpress/?page_id=494 Introduction Lisp (1958)

More information

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

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

More information

Lisp. Versions of LISP

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

More information

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

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

More information

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

LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. 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,

More information

ALISP interpreter in Awk

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.

More information

Symbols are more than variables. Symbols and Property Lists. Symbols are more than variables. Symbols are more than variables.

Symbols are more than variables. Symbols and Property Lists. Symbols are more than variables. Symbols are more than variables. Symbols are more than variables So far we have been looking at symbols as if they were variables Symbols and Property Lists Based on Chapter 7 in Wilensky + Prof. Gotshalks notes on symbols > ( setq x

More information

Functional programming with Common Lisp

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

More information

Functional Programming. Pure Functional Programming

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).

More information

Associative Database Managment WIlensky Chapter 22

Associative Database Managment WIlensky Chapter 22 Associative Database Managment WIlensky Chapter 22 DB-1 Associative Database An associative database is a collection of facts retrievable by their contents» Is a poodle a dog? Which people does Alice manage?»

More information

CSCI337 Organisation of Programming Languages LISP

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

More information

Problems 3-1, 3.3, 3.4 and 3.5 in Chapter 3 of Winston and Horn's LISP (see Below)

Problems 3-1, 3.3, 3.4 and 3.5 in Chapter 3 of Winston and Horn's LISP (see Below) Homework Solutions: Problem Set Homework 2 Due uesday September 8, 2015 in class Be sure to follow the guidelines for Programming Assignments. Since these problems are simple, you may skip the Statement

More information

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

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

More information

Turtles All The Way Down

Turtles All The Way Down Turtles All The Way Down Bertrand Russell had just finished giving a public lecture on the nature of the universe. An old woman said Prof. Russell, it is well known that the earth rests on the back of

More information

Imperative, OO and Functional Languages A C program is

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,

More information

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

(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

More information

Review of Functional Programming

Review of Functional Programming Review of Functional Programming York University Department of Computer Science and Engineering 1 Function and # It is good programming practice to use function instead of quote when quoting functions.

More information

Lambda Calculus see notes on Lambda Calculus

Lambda Calculus see notes on Lambda Calculus Lambda Calculus see notes on Lambda Calculus Shakil M. Khan adapted from Gunnar Gotshalks recap so far: Lisp data structures basic Lisp programming bound/free variables, scope of variables Lisp symbols,

More information

A little bit of Lisp

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

More information

CS61A Midterm 2 Review (v1.1)

CS61A Midterm 2 Review (v1.1) Spring 2006 1 CS61A Midterm 2 Review (v1.1) Basic Info Your login: Your section number: Your TA s name: Midterm 2 is going to be held on Tuesday 7-9p, at 1 Pimentel. What will Scheme print? What will the

More information

Robot Programming with Lisp

Robot Programming with Lisp 4. Functional Programming: Higher-order Functions, Map/Reduce, Lexical Scope Institute for Artificial University of Bremen 9 of November, 2017 Functional Programming Pure functional programming concepts

More information

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

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

More information

Associative Database Managment

Associative Database Managment Associative Database Managment WIlensky Chapter 22 DB-1 Associative Database An associative database is a collection of facts retrievable by their contents» Is a poodle a dog? Which people does Alice manage?»

More information

Midterm Examination (Sample Solutions), Cmput 325

Midterm Examination (Sample Solutions), Cmput 325 Midterm Examination (Sample Solutions, Cmput 325 [15 marks] Consider the Lisp definitions below (defun test (L S (if (null L S (let ((New (add (cdar L S (test (cdr L New (defun add (A S (if (null S (cons

More information

UMBC CMSC 331 Final Exam

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

More information

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

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

More information

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am. The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction! Numeric operators, REPL, quotes, functions, conditionals! Function examples, helper

More information

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

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

More information

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. 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

More information

Functional Programming. Pure Functional Languages

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

More information

Project 2: Scheme Interpreter

Project 2: Scheme Interpreter Project 2: Scheme Interpreter CSC 4101, Fall 2017 Due: 12 November 2017 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same

More information

Imperative languages

Imperative languages Imperative languages Von Neumann model: store with addressable locations machine code: effect achieved by changing contents of store locations instructions executed in sequence, flow of control altered

More information

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

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

More information

(penguin-rule (if (animal-x is bird) (animal-x can swim)) (then (animal-x is penguin))) (?x is bird)

(penguin-rule (if (animal-x is bird) (animal-x can swim)) (then (animal-x is penguin))) (?x is bird) 93 10 1993.11.15 1 1.1 (penguin-rule (if (animal-x is bird) (animal-x can swim)) (then (animal-x is penguin))) (animal-x) 3 animal-y animal-z 1 (penguin-rule (if (?x is bird) (?x can swim)) (then (?x is

More information

Introduction to Lisp

Introduction to Lisp Last update: February 16, 2010 Introduction to Lisp Dana Nau Dana Nau 1 Outline I assume you know enough about computer languages that you can learn new ones quickly, so I ll go pretty fast If I go too

More information

Recursion & Iteration

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

More information

Introduction to LISP. York University Department of Computer Science and Engineering. York University- CSE V.

Introduction to LISP. York University Department of Computer Science and Engineering. York University- CSE V. Introduction to LISP York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 11_LISP 1 Introduction to LISP Evaluation and arguments S- expressions Lists Numbers

More information

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, 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

More information

Documentation for LISP in BASIC

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

More information

Introduction to Functional Programming and basic Lisp

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

More information

History. Functional Programming. Based on Prof. Gotshalks notes on functionals. FP form. Meaningful Units of Work

History. Functional Programming. Based on Prof. Gotshalks notes on functionals. FP form. Meaningful Units of Work History Functional Programming Based on Prof. Gotshalks notes on functionals 1977 Turing 1 Lecture John Backus described functional programming The problem with current languages is that they are word-at-a-time

More information

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007 CSCI 3155: Principles of Programming Languages Exam preparation #1 2007 Exercise 1. Consider the if-then-else construct of Pascal, as in the following example: IF 1 = 2 THEN PRINT X ELSE PRINT Y (a) Assume

More information

Func%onal Programming in Scheme and Lisp

Func%onal Programming in Scheme and Lisp Func%onal Programming in Scheme and Lisp http://www.lisperati.com/landoflisp/ Overview In a func(onal programming language, func(ons are first class objects You can create them, put them in data structures,

More information

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

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,

More information

Notes on Higher Order Programming in Scheme. by Alexander Stepanov

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

More information

An Explicit-Continuation Metacircular Evaluator

An Explicit-Continuation Metacircular Evaluator Computer Science (1)21b (Spring Term, 2018) Structure and Interpretation of Computer Programs An Explicit-Continuation Metacircular Evaluator The vanilla metacircular evaluator gives a lot of information

More information

User-defined Functions. Conditional Expressions in Scheme

User-defined Functions. Conditional Expressions in Scheme User-defined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment

More information

Func%onal Programming in Scheme and Lisp

Func%onal Programming in Scheme and Lisp Func%onal Programming in Scheme and Lisp http://www.lisperati.com/landoflisp/ Overview In a func(onal programming language, func(ons are first class objects You can create them, put them in data structures,

More information

Vectors in Scheme. Data Structures in Scheme

Vectors in Scheme. Data Structures in Scheme Data Structures in Scheme Vectors in Scheme In Scheme, lists and S-expressions are basic. Arrays can be simulated using lists, but access to elements deep in the list can be slow (since a list is a linked

More information

Announcements. Today s Menu

Announcements. Today s Menu Announcements 1 Today s Menu Sample A* Problem A* Code Traveling Salesman - Brute Force {See Traveling_Salesman.ppt } 2 Heuristic Searches The following figure shows a search tree with the state indicated

More information

Functional Programming

Functional Programming Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

More information

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

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

More information

MIDTERM EXAMINATION - CS130 - Spring 2005

MIDTERM EXAMINATION - CS130 - Spring 2005 MIDTERM EAMINATION - CS130 - Spring 2005 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 231 + 25 extra credit This exam counts for 25%

More information

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

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,

More information

Functional Programming. Big Picture. Design of Programming Languages

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

More information

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

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,

More information

by the evening of Tuesday, Feb 6

by the evening of Tuesday, Feb 6 Homework 1 Due 14 February Handout 6 CSCI 334: Spring 2018 Notes This homework has three types of problems: Self Check: You are strongly encouraged to think about and work through these questions, and

More information

Chapter 15 Functional Programming Languages

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.

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages CSc 520 Principles of Programming Languages 9: Scheme Metacircular Interpretation Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian

More information

Allegro CL Certification Program

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

More information

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

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,

More information

Functional Programming. Pure Functional Languages

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

More information

CSCI 2210: Programming in Lisp. Progn. Block. CSCI Programming in Lisp; Instructor: Alok Mehta 1. ANSI Common Lisp, Chapters 5-10

CSCI 2210: Programming in Lisp. Progn. Block. CSCI Programming in Lisp; Instructor: Alok Mehta 1. ANSI Common Lisp, Chapters 5-10 CSCI 2210: Programming in Lisp ANSI Common Lisp, Chapters 5-10 CSCI 2210 - Programming in Lisp; Instructor: Alok Mehta; 4.ppt 1 Progn Progn Creates a block of code Expressions in body are evaluated Value

More information

Jatha. Common Lisp in Java. Ola Bini JRuby Core Developer ThoughtWorks Studios.

Jatha. Common Lisp in Java. Ola Bini JRuby Core Developer ThoughtWorks Studios. Jatha Common Lisp in Java Ola Bini JRuby Core Developer ThoughtWorks Studios ola.bini@gmail.com http://olabini.com/blog Common Lisp? Common Lisp? ANSI standard Common Lisp? ANSI standard Powerful Common

More information

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

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

More information

Functions, Conditionals & Predicates

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)

More information

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

;; 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

More information

CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

More information

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Scheme in Scheme: The Metacircular Evaluator Eval and Apply Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,

More information

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

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.

More information

CS 314 Principles of Programming Languages. Lecture 16

CS 314 Principles of Programming Languages. Lecture 16 CS 314 Principles of Programming Languages Lecture 16 Zheng Zhang Department of Computer Science Rutgers University Friday 28 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:

More information

19 Machine Learning in Lisp

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

More information

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

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

More information

Functional Programming with Common Lisp

Functional Programming with Common Lisp Functional Programming with Common Lisp Kamen Tomov ktomov@hotmail.com July 03, 2015 Table of Contents What is This About? Functional Programming Specifics Is Lisp a Functional Language? Lisp Says Hi Functional

More information

UMBC CMSC 331 Final Exam

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

More information

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page. MORE SCHEME COMPUTER SCIENCE MENTORS 61A October 30 to November 3, 2017 1 What Would Scheme Print? Solutions begin on the following page. 1. What will Scheme output? Draw box-and-pointer diagrams to help

More information

A Quick Introduction to Common Lisp

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

More information

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8 Question 1. (12 points) For each of the following, what value is printed? (Assume that each group of statements is executed independently in a newly reset Scheme environment.) (a) (define x 1) (define

More information

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? 2. How does memoization work?

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? 2. How does memoization work? STREAMS 10 COMPUTER SCIENCE 61AS Basics of Streams 1. What is a stream? 2. How does memoization work? 3. Is a cons-stream a special form? Practice with Streams 1. Define a procedure (ones) that, when run

More information

Evaluating Scheme Expressions

Evaluating Scheme Expressions Evaluating Scheme Expressions How Scheme evaluates the expressions? (procedure arg 1... arg n ) Find the value of procedure Find the value of arg 1 Find the value of arg n Apply the value of procedure

More information

SOFTWARE ARCHITECTURE 6. LISP

SOFTWARE ARCHITECTURE 6. LISP 1 SOFTWARE ARCHITECTURE 6. LISP Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Compiler vs Interpreter Compiler Translate programs into machine languages Compilers are

More information

Functional Programming. Contents

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...

More information

Basics of Using Lisp! Gunnar Gotshalks! BLU-1

Basics of Using Lisp! Gunnar Gotshalks! BLU-1 Basics of Using Lisp BLU-1 Entering Do Lisp work Exiting Getting into and out of Clisp % clisp (bye)» A function with no arguments» CTRL d can also be used Documentation files are in the directory» /cse/local/doc/clisp

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I

Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I by John McCarthy Ik-Soon Kim Winter School 2005 Feb 18, 2005 Overview Interesting paper with By John Mitchell Interesting

More information

CS 314 Principles of Programming Languages

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.

More information

Introduction to Scheme

Introduction to Scheme How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free

More information

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information