Commands and predicates LISP functions are divided into 2 classes. Predicates are functions that return boolean values i.e. t or nil. The rest are commands.

Slides:



Advertisements
Similar presentations
Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Advertisements

ANSI Common Lisp 3. Lists 20 June Lists Conses List Functions Trees Sets Stacks Dotted Lists Assoc-lists.
Arrays.
CIS100 Test 2 Review REACH CRC © 2011 REACH CRC. All Rights Reserved.Spring 2011.
Chapter 12 File Processing and Data Management Concepts
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
List manipulation Consider student database, where each student is represented by the following list: * (setf student1 '((Paul Bennett) ((hw1 4.3) (hw2.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
Arrays (1) You create an array in LISP by using the function (make- array ). All elements are initially set to nil. To create a 1-dimensional array of.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
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.
Sixteen lists and compound data. Recap Names: constants and variables When evaluated, return a specific data objects Can make new names with: [define.
CS 330 Programming Languages 11 / 20 / 2007 Instructor: Michael Eckmann.
CS 330 Programming Languages 11 / 18 / 2008 Instructor: Michael Eckmann.
Fourteen lists and compound data. Some primitive data types Integers (whole numbers) 1, 2, 3, -1, 0, , etc. “Floating-point” numbers ,
How to define functions? (DEFUN function-name parameter-list commands ) Example: (DEFUN myFunction (x y) (/ x y) ) To call this function, you would then.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Data Structures Using C++1 Chapter 13 Standard Template Library (STL) II.
2.3 Cool features in C# academy.zariba.com 1. Lecture Content 1.Extension Methods 2.Anonymous Types 3.Delegates 4.Action and Func 5.Events 6.Lambda Expressions.
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
1 Iterators & Algorithms Iterators provide a link between containers and algorithms Example: We wish to write a function sum() that adds up the members.
Logical functions and - Logical AND function. Example: (and (> 5 4) (< 5 4)) or - Logical OR function. Example: (and (> 5 4) (< 5 4)) not - Logical negation.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
Advanced Functions In CL, functions are often supplied as parameters to other functions –This gives us tremendous flexibility in writing functions whose.
Chapter 10 Review: Matrix Algebra
Digital Electronics Data Structures LISP
Alok Mehta - Programming in Lisp - Data Abstraction and Mapping Programming in Lisp Data Abstraction and Mapping.
Copyright © Curt Hill Other Trees Applications of the Tree Structure.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
PRACTICAL COMMON LISP Peter Seibel 1.
Mitthögskolan 10/8/ Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it.
Multiple Returns and Extra Parameters “LISP is unique in its capability to return more than one value (or no value at all) from a form. This neatly avoids.
Lisp Laboratory gcLisp (Golden Common Lisp). Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon.
CSC271 Database Systems Lecture # 12. Summary: Previous Lecture  Row selection using WHERE clause  WHERE clause and search conditions  Sorting results.
Data Structures Using C++ 2E Chapter 13 Standard Template Library (STL) II.
Built-in Data Structures in Python An Introduction.
Machaut Messe Performance Performance Performance Isorhythm Isorhythm.
1 Iterators Good reference site:
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
Building user-defined functions: the progressive envelopment technique The idea: define combinations of LISP primitives through a sequence of experiments.
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
PRACTICAL COMMON LISP Peter Seibel 1.
Control in LISP More on Predicates & Conditionals.
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.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
CS 330 Programming Languages 11 / 28 / 2006 Instructor: Michael Eckmann.
1 Artificial Intelligence CS370D Prolog programming List operations.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Copyright © Curt Hill Other Trees Applications of the Tree Structure.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Fortran: Control Structures Session Three ICoCSIS.
A Level Computing#BristolMet Session Objectives#U2S11 MUST identify built-in string manipulation functions SHOULD correctly use string manipulation functions.
Recursion ITI 1121 N. El Kadri. Reminders about recursion In your 1 st CS course (or its equivalent), you have seen how to use recursion to solve numerical.
Comparative Programming Languages Functional programming with Lisp/Scheme.
Modern Programming Languages Lecture 20 Fakhar Lodhi
J.E. Spragg Mitthögskolan 1997
Imperative Data Structures
Data Structures in Lisp
LISP: Basic Functionality
Data Structures in Lisp
LISP: Basic Functionality
Allegro CL Certification Program
List manipulation Consider student database, where each student is represented by the following list: * (setf student1 '((Paul Bennett) ((hw1 4.3) (hw2.
Maths Unit 7 (F) – Equations & Sequences
Presentation transcript:

Commands and predicates LISP functions are divided into 2 classes. Predicates are functions that return boolean values i.e. t or nil. The rest are commands. Functions CommandsPredicates

Sequences (1) Sequences ListsVectors* *Vectors are 1-dimensional array.

Sequences (2) Sequences contain elements which are ordered. Nil is taken to be a sequence of length zero. Common Lisp provides a set of functions to manipulate sequences. We have seen some of these functions in the previous session, such as length, reverse…

Searching lists: find (1) This function is used to search for the occurrence of a particular element within a list. Syntax: (find element list). Example: (find 10 ‘(1 2 3)) (if (find ‘a ‘(a b c)) ‘Yes ‘No)

find (2) To specify a function to use when comparing the entry to each element of the list, you should use :test (find 3 ‘( ) :test #’<) The above expression will return the first element of the specified list that satisfies the function ‘>’. It will return 4.

find (3) To tell LISP which part of each element of the list to compare to the supplied entry, use :key (find ‘A ‘((A B) (C D E) (F G H I)):key #’first) To put it in words, the above statement means that “is there any element within the supplied nested list whose first element is the atom A?”

find-if Find-if is used to find an element of a list that satisfies some predicate. Syntax: (find-if predicate list) For example: (find-if #’evenp ‘( )) This will return the first element of the given list that satisfies the predicate evenp. Another example: (find-if #’oddp ‘((0 1) (1 2)) :key #’first)

find-if-not Find-if-not searches for the first element of a given list that fails a specified predicate. Try replacing the find-if in the previous example with find-if-not.

Filtering lists: remove Remove returns a new list similar to the supplied list, except that all the occurrences of the given entry removed. (remove 1 ‘((0 1) (1 2) (2 3)) :key #’first) The above expression will remove from the parent list, all child lists whose first element equals 1.

remove-if Remove-if is identical to the above, except that you would supply a predicate, and all elements within the supplied list that satisfies that predicate will be removed. (remove-if #’evenp ‘( )) The above statement will remove all occurrences of even numbers from the given list.