John McCarthy IBM 704

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

CS 314 Principles of Programming Languages

FP Foundations, Scheme

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

Functional Languages. Hwansoo Han

Functional Programming. Pure Functional Languages

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

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

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Functional Programming. Pure Functional Languages

Common LISP Tutorial 1 (Basic)

Introduction to Functional Programming and basic Lisp

Documentation for LISP in BASIC

Func%onal Programming in Scheme and Lisp

Programming Languages

LECTURE 16. Functional Programming

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

by the evening of Tuesday, Feb 6

Functional Programming. Big Picture. Design of Programming Languages

Imperative, OO and Functional Languages A C program is

Lambda Calculus see notes on Lambda Calculus

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

Modern Programming Languages. Lecture LISP Programming Language An Introduction

MIDTERM EXAMINATION - CS130 - Spring 2005

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

Func%onal Programming in Scheme and Lisp

Lecture Notes on Lisp A Brief Introduction

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

Functional Programming. Pure Functional Programming

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003

Lisp Basic Example Test Questions

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

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

SOFTWARE ARCHITECTURE 6. LISP

Programming Systems in Artificial Intelligence Functional Programming

Imperative languages

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

Sample Final Exam Questions

Organization of Programming Languages CS3200/5200N. Lecture 11

Introduction to ACL2. CS 680 Formal Methods for Computer Verification. Jeremy Johnson Drexel University

A brief tour of history

CSCI 334: Principles of Programming Languages. Lecture 2: Lisp Wrapup & Fundamentals. Higher-Order Functions. Activity

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

CS 314 Principles of Programming Languages. Lecture 16

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

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Symbolic Computation and Common Lisp

Review of Functional Programming

SCHEME AND CALCULATOR 5b

Lecture #2 Kenneth W. Flynn RPI CS

Functional Programming

Lecture #24: Programming Languages and Programs

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

Lisp. Versions of LISP

A little bit of Lisp

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

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Functional Programming - 2. Higher Order Functions

CS 415 Midterm Exam Spring 2002

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

Project 2: Scheme Interpreter

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

A Small Interpreted Language

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Functional Programming Lecture 1: Introduction

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

CS 415 Midterm Exam Fall 2003

CSc 520 Principles of Programming Languages

Topic III. LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Associative Database Managment WIlensky Chapter 22


A Quick Introduction to Common Lisp

Associative Database Managment

CSCI337 Organisation of Programming Languages LISP

Functional programming in LISP

Functional Programming. Contents

Heap storage. Dynamic allocation and stacks are generally incompatible.

UMBC CMSC 331 Final Exam Section 0101 December 17, 2002

Functional Programming

More Scheme CS 331. Quiz. 4. What is the length of the list (()()()())? Which element does (car (cdr (x y z))) extract from the list?

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

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

LISP Programming. (23 (this is easy) hello 821)

CS 360 Programming Languages Interpreters

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

4/19/2018. Chapter 11 :: Functional Languages

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

User-defined Functions. Conditional Expressions in Scheme

Detection of methods (or missing methods): Cleaning up some details of our implementation. Better Method Convention (1) --self

Robot Programming with Lisp

Introduction to Functional Programming in Haskell 1 / 56

Midterm Examination (Sample Solutions), Cmput 325

CS 314 Principles of Programming Languages

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

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

Common Lisp. Blake McBride

CS 242. Fundamentals. Reading: See last slide

The Design and Implementation of a Modern Lisp. Dialect

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

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

Transcription:

How this course works SI 334: Principles of Programming Languages Lecture 2: Lisp Instructor: an arowy Lots of new languages Not enough class time to cover all features (e.g., Java over the course of 34-36: year!) Read the assigned book chapters, read course tutorials, and even seek additional material on your own (on teh Googles) Ts/office hours John Mcarthy IM 74

Lisp was invented for I research 74 ssembly (circa 954) (From oding the MIT-IM 74 omputer) (defun fact (n) (cond ((eq n ) ) (t (* n (fact (- n )))))) FORTRN (circa 956) (From NS Technical Note -737) LISP (circa 958)

LISP is a functional language programs are modeled after math. functions no statements, only expressions no mutable variables, only declarations therefore, the effect of running a program ( evaluation ) is purely the effect of applying a function to an input. LISP is a functional language 3 + 4 (defun add-one (n) n + ) LISP is a functional language dirty house ig functions are composed of little functions dirty house www www clean house (defun cleaning-robot (dirt) ) clean house (defun cleaning-robot (dirt) )

Program correctness is easier to achieve dirty house www clean house I.e., whole is correct if pieces are correct. LISP is inspired by the lambda calculus everything either a value or a funct. of a value value: function of two values: (+ ) syntax is (mind-numbingly) regular functions: (function-name arguments ) values: anything that is not a function evaluating a function produces a value: (+ )=2 Statements vs. expressions statement is an operation that changes the state of the computer Java: i++ value stored at location i incremented by one n expression is a combination of functions and values that yields a new value Lisp: (+ i ) evaluating + with i and returns i + RPL (read-eval-print loop)

Mutable variables atch mode If you can update a variable in a language, you have mutable variables Java: int i = 3; i = 4; Notice that both lines of code are statements (pure) Lisp does not have mutable variables Immutable variables Variables cannot be updated in Lisp Lisp: (defun my-func (i) ) (my-func 3) or the shorter ((lambda (i) ) 3) Notice that all of the above are expressions In fact, functions are the only way to bind values to names in (pure) Lisp Lisp syntax: atoms n atom is the most basic unit in Lisp: data 4 2.75 hello foo t nil

Lisp syntax: cons cells Lisp syntax: lists The cons cell allows composing values (cons hello 4).g., lists in Lisp are just made out of cons cells (cons (cons 2 (cons 3 nil))) 2 3 hello 4 Lisp has a shorthand for this: ( 2 3) Lisp syntax: car and cdr ccess the first element of a cons cell with car (car (cons 2)) = ccess the second element with cdr (cdr (cons 2)) = 2 What s the value of the following expression? (car ( 2 3)) What about this? (cdr ( 2 3)) Lisp syntax: functions verything else is a function (or special form) There are a bunch of built-in functions (car ) (cdr ) (append ), etc. nd you can define your own (defun my-func (arg) (value))

Lisp syntax: conditionals In Lisp, there is no if/else (cond ((test) (value)) ).g., (cond ((eq x) (cons x xs)) ) oes the same as the Java if (x == ) { } xs.add(x); Lisp syntax: conditionals cond is more general than if/else. (cond ((test) (value)) ((test2) (value2) ) (defun insert (x l) (cond ((eq l nil) (cons x nil)) ((< x (car l)) (cons x l)) (t (cons (car l) (insert x (cdr l)))))) That s pretty much it! Note that the book uses slightly different syntax You should use: t instead of true (defun ) instead of (define ) (mapcar # f xs) instead of (maplist f xs) See 334 Lisp FQ for all the syntax you need to know on course webpage ctivity list length

adger ctivity ow el Memory management : When you want to use a variable, you have to allocate it first, then decallocate it when done. MyObject *m = malloc(sizeof(myobject)); ardvark onkey Fox m->foo = 2; m->bar = 3; do stuff with m free(m); Memory management Lisp and Java: You barely need to think about this at all. MyObject m = new MyObject(2,3); Lisp memory model ons cell: tom: ddress tom ecrement value (cons ' (cons ' (cons ' nil))) do stuff with m (cons 2 3) tom tom nil tom

Sharing data Garbage collection (a) (b) oth structures could be printed as (.).(.) What is result of evaluating (cons (cons ) (cons ))? Garbage collection. lear tags

2. Mark reachable cells 2. Mark reachable cells 2. Mark reachable cells 2. Mark reachable cells

2. Mark reachable cells 3. Free unreachable cells