Questions?.

Slides:



Advertisements
Similar presentations
Messiaen Quartet for the end of time And another.
Advertisements

Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
1 Programming Languages and Paradigms Lisp Programming.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
Paul Lunn BSc(Hons) MSc PCPD FHEA MIET Supervised by Dr A Hunt ( Department of Electronics, The University of York)
Tail Recursion. Problems with Recursion Recursion is generally favored over iteration in Scheme and many other languages It’s elegant, minimal, can be.
Helper functions: when extra arguments are needed Consider this problem: we want a function index_items that takes a list L and gives a number to each.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
A function (negatives L) that takes a list of numbers L and returns a list containing only negative numbers from L. A recursive example to remind you (defun.
מבוא מורחב - שיעור 91 Lecture 9 Lists continued: Map, Filter, Accumulate, Lists as interfaces.
1 Chapter 9 Maps and Dictionaries. 2 A basic problem We have to store some records and perform the following: add new record add new record delete record.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
Common Lisp! John Paxton Montana State University Summer 2003.
Imperative programming public int factorial (int N){ int F = 1; for(X=N; X>1; X-- ){ F= F*X; } return F; } Functional programming (defun factorial(N) (cond.
Structured programming
Data Abstraction… The truth comes out…. What we’re doing today… Abstraction ADT: Dotted Pair ADT: List Box and Pointer List Recursion Deep List Recursion.
>(setf oldlist ) Constructing a list We know how to make a list in lisp; we simply write it: ‘4321( ) What if we want a new list with that list as a part?
Plans for Today Chapter 2: Intelligent Agents (until break) Lisp: Some questions that came up in lab Resume intelligent agents after Lisp issues.
CSE S. Tanimoto Explicit Function Application 1 Explicit Application of Functions, Functional Arguments and Explicit Evaluation Implicit and explicit.
Mapping And Iteration So far, the only Lisp mechanism we have considered, which allows an action to be performed repeatedly is recursion. Most programming.
מבוא מורחב - שיעור 81 Lecture 8 Lists and list operations (continue).
Programming in Lisp; Instructor: Alok Mehta Programming in Lisp Recursion, Data Abstraction, Mapping, Iteration.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
General pattern for selecting some elements of a list This negatives example illustrates a general pattern: If you want a function which selects some elements.
Final Projects Some simple ideas. Composition (1) program that "learns" some aspect of musical composition.
Problem Solving with Data Structures using Java: A Multimedia Approach Chapter 5: Arrays: A Static Data Structure for Sounds.
Arbitrarily Long Data Structures: Lists and Recursion CMSC Introduction to Computer Programming October 4, 2002.
Common lisp A functional programming language. Useful URL:
Analyzing Complexity of Lists OperationSorted Array Sorted Linked List Unsorted Array Unsorted Linked List Search( L, x ) O(logn) O( n ) O( n ) Insert(
1 CS 177 Week 16 Recitation Recursion. 2 Objective To understand and be able to program recursively by breaking down a problem into sub problems and joining.
1 Append: process  (append list1 list2) (cons 1 (append ‘(2) list2)) (cons 1 (cons 2 (append ‘() list2))) (cons 1 (cons 2 list2)) (define (append list1.
Lecture 6-2CS250: Intro to AI/Lisp Programming in Your Favorite Language Lecture 5-2 February 11 th, 1999 CS250.
Basic LISP Programming Common LISP follows the algorithm below when interacting with users: loop read in an expression from the console; evaluate the expression;
Function Design in LISP. Program Files n LISP programs are plain text –DOS extensions vary; use.lsp for this course n (load “filename.lsp”) n Can use.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Recursive Definitions of Properties of Data Structures  Recursive.
Final Projects Some simple ideas. Composition (1) program that "learns" some aspect of musical composition.
Operating on Lists Chapter 6. Firsts and Seconds n Transforming list of pairs into two lists –(firsts ‘((1 5) (2 6) (3 7)))  (1 2 3) –(seconds ‘((1 5)
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Dynamic Programming & Memoization. When to use? Problem has a recursive formulation Solutions are “ordered” –Earlier vs. later recursions.
CSE 341, S. Tanimoto Lisp Explicit Application of Functions and Functional Arguments In Lisp, functions can be passed as arguments to other functions.
RetrogradeRetrograde. Divide and Conquer Concept first Data: ‘(( )( )) We want this to look like ‘(( )(500.
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
Tail Recursion.
Intelligent Agents Lecture 3-2 October 14th, 1999 CS250 Lecture 2-1
CS 550 Programming Languages Jeremy Johnson
Racket CSC270 Pepper major portions credited to
CS 270 Math Foundations of CS Jeremy Johnson
Lecture 16 Arithmetic Circuits
6.001 SICP Data abstractions
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
Lecture #8 מבוא מורחב.
Open your video file. Play the video.
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE S. Tanimoto Explicit Function Application
Explicit Application of Procedures, and Explicit Evaluation
Lisp: Using Functions as Data
Noise Pollution D. Crowley, 2008.
Lecture #7 מבוא מורחב.
List and list operations (continue).
Peter Seibel Practical Common Lisp Peter Seibel
Today’s topics Abstractions Procedural Data
Lisp: Using Functions as Data
Lecture # , , , , מבוא מורחב.
Recursion Chapter 12.
Programming Languages
Lisp.
The general format of case is the following: (case <key form>
LISP primitives on sequences
Presentation transcript:

Questions?

From (0 60 1000 1 64) get: 1) 0 2) 64 3) 1000 4) (1000 1 64) 5) (60 1000) 6) (0 60 1000) 7) (0 1) 8) ((0)) 9) (60 1000 64) 10) (60 0)

From (((a) b) c) get: 1) a 2) c 3) b 4) (a b) 5) (a (b c)))

From (a b c d e) get: 1) (d e) 2) 5 3) (a (b (c (d (e))))) 4) (e d c b a) 5) (a b c d)

From a get: 1) (a) 2) (a . a) 3) (a (a)) 4) ((a) a) 5) (a ())

From a and (b c) get: 1) (a b c) 2) ((a) b c) 3) (a (b c)) 4) (a c) 5) (c b a)

From (a b) and (c d) get: 1) (a b c d) 2) ((a b) c d) 3) ((a b)(c d)) 4) (b a d c) 5) (a (b c) d)

(append '((1)) '(2 3))

((1) 2 3)

(append '((2)(3)) '(4 5))

((2) (3) 4 5)

(first '(((a)) (b c d e)))

((A))

(rest '(((((f))))))

nil

(first '(rest (a b c)))

rest

(first (second '(((1 2))(2 3 4)((5 6 7)))))

2

(second (first '(((1 2))(2 3 4)((5 6 7)))))

nil

Define a function AVERAGE that returns the average of 5 numbers: (average 1 2 3 4 5) returns 3.

(defun average (n1 n2 n3 n4 n5) (coerce (/ (+ n1 n2 n3 n4 n5) 5) 'float)) ; ? (average 1 2 3 4 5) ; 3.0 ; ? (average 1 2 3 4 6) ; 3.2

Sonification Sound from data not intended to create sound. Both scientific and artistic value.

Pleiades Large scale radio telescope Ability to view data in standard ways Ability to usefully hear data in order to find patterns otherwise not perceivable Musically interesting sonifications SETI (Search for Extraterrestrial Life)

Pleiades Data from the planet Jupiter Data selected by Cope Data sonified by Peter Elsea (mid-80s) Saturday night Pleiades by Cope Sonification of planet Mars (2002 or so)

Sonification Where do you begin? Where do you go from there? What do you want to have as output?

Divide and Conquer Find interesting data Ensure it’s diverse enough Lispify it (listify) Normalize the data to MIDI range Produce cope-events. Save as MIDI file and play.

Sonification What criteria to use in finding data?

Data Astronomical Stocks Temperatures Seismological Measurements Bit maps

DATA How do you get the data into musical shape? The process is known as normalization How do you achieve normalization?

Normalization Compare range of one list to another (/) Multiply by known element of first list (minus it’s lowest range level) Add in lower MIDI range Round it to avoid floats New MIDI note

Recursion The ability of a function to do the same thing to an arbitrary length list of data The ability of a function to call itself The ability of a function to automatically stop at the end of its argument The ability of a function to return the changed data in appropriate order

Add-One Data: ‘(1 2 3 4 5 6 7) Process: add one to each number (cons (+ 1 7) ()) (cons (+ 1 6) (cons (+ 1 7) ()) (cons (+ 1 5) (cons (+ 1 6) (cons (+ 1 7) ()) And so on?

In other words (cons n3 (cons n2 (cons n1 (cons n0 ())))

Recursion (defun add-one (list-of-numbers)

Ending You must have code to end the function first in order to make sure the function ends with an empty list as second argument to the final call to cons.

Continuation (defun add-one (list-of-numbers) (if (null list-of-numbers) ()

Continuation (defun add-one (list-of-numbers) (if (null list-of-numbers) () (cons (+ 1 (first list-of-numbers))

Continuation (defun add-one (list-of-numbers) (if (null list-of-numbers) () (cons (+ 1 (first list-of-numbers)) (add-one (rest list-of-numbers))))

It works ? (add-one ‘(1 2 3 4 5 6 7)) (2 3 4 5 6 7 8)