ANSI Common Lisp 4. Specialized Data Structures 7 June 2003.

Slides:



Advertisements
Similar presentations
CS 63 LISP Philip Greenspun's Tenth* Rule of Programming:
Advertisements

ANSI Common Lisp 3. Lists 20 June Lists Conses List Functions Trees Sets Stacks Dotted Lists Assoc-lists.
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Container Types in Python
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Generics "It is easy to study the rules of overloading and of templates without noticing that together they are one of the keys to elegant and efficient.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
Lisp Recitation (cse471/598 Fall 2007 ) Aravind Kalavagattu.
1 LISP III. 2 Functional programming l Definition From the "comp.lang.functional FAQ" Functional programming is a style of programming that emphasizes.
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.
Common Lisp! John Paxton Montana State University Summer 2003.
Procedures with optional parameters which do not require matching arguments Example: consider the exponent function which may take one argument, m, in.
Project 1: Background Informed search : 8- puzzle world BFS, DFS and A* algorithms Heuristics : Manhattan distance, Number of misplaced tiles Lisp programming.
Representing Data Elements Gayatri Gopalakrishnan.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
CSCI Programming in Lisp; Instructor: Alok Mehta; 3_structs.ppt1 CSCI 2210: Programming in Lisp Programming Techniques Data Structures More Built-in.
Returning values from functions You can return a value from a function by using the built- in function : ( return-from Function_name value) For example:
CMSC 471 LISP. Why Lisp? Because it’s the most widely used AI programming language Because it’s good for writing production software (Graham article)
COMP 205 – Week 11 Dr. Chunbo Chu. Intro Lisp stands for “LISt Process” Invented by John McCarthy (1958) Simple data structure (atoms and lists) Heavy.
CSE 341, S. Tanimoto Lisp Data Structures - 1 Data Structures in Lisp 0. Collections of associations, association lists. 1. Creating graphs with conses.
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.
Allegro CL Certification Program Lisp Programming Series Level I Session Top Ten Things to Know.
Functional Programming
Functional Programming 02 Lists
1 Othello Game Programs (human to human). 2 (defconstant all-directs '( )) ALL-DIRECTS (defconstant empty 0) EMPTY (defconstant.
CSE473 Winter /09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
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.
Lecture 2-1CS250: Intro to AI/Lisp Intelligent Agents Lecture 3-2 October 14 th, 1999 CS250.
1 More About Lisp. 2 Functions on Lists (setf x '(a b c)) => (A B C) (setf y '(1 2 3)) => (1 2 3) (rest x) => (B C) ;;all but the first element (nth 1.
Artificial Intelligence IES 503 Asst. Prof. Dr. Senem Kumova Metin.
06 INPUT AND OUTPUT Functional Programming. Streams Two kinds of streams  Character streams  Binary streams Character streams are Lisp objects representing.
C++ Character Set It is set of Characters/digits/symbol which is valid in C++. Example – A-Z, (white space) C++ Character Set It is set of.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Lecture 6-2CS250: Intro to AI/Lisp Programming in Your Favorite Language Lecture 5-2 February 11 th, 1999 CS250.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Lisp Files, Arrays, and Macros CIS 479/579 Bruce R. Maxim UM-Dearborn.
Beyond Lists: Other Data Structures Lisp would still be a pretty decent programming language if it only contained atoms and lists –But we can go far beyond.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
PRACTICAL COMMON LISP Peter Seibel 1.
11 Speed & Debug.  Lisp is really two languages:  A language for writing fast programs  A language for writing programs fast  In the early stage,
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
PRACTICAL COMMON LISP Peter Seibel 1.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
1 Variable Declarations Global and special variables – (defvar …) – (defparameter …) – (defconstant …) – (setq var2 (list 4 5)) – (setf …) Local variables.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Lists CSC 358/ Outline Lab #1 / Homework #1 Lists A question List Internals of Lists List operations Extended Example.
Basic Introduction to Lisp
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
PRACTICAL COMMON LISP Peter Seibel 1.
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
Macros CSC 358/ Outline  Homework #6  Macro Intro  Backquote  Macros  Modify macros  Read Macros.
Strings … operators Up to now, strings were limited to input and output and rarely used as a variable. A string is a sequence of characters or a sequence.
Common LISP VS JAVA 김민철. Table of contents  1. LISP …………………………………………… 3  2. 데이터 타입 …………………………………… 4  3. 산술 및 논리 연산 ……………………………… 8  4. 변수 선언 및 할당 ………………………………
2 Arrays Array is a data structure that represents a collection of the same type of data. A "fixed length list".
Intelligent Agents Lecture 3-2 October 14th, 1999 CS250 Lecture 2-1
Modern Programming Languages Lecture 20 Fakhar Lodhi
Data Structures in Lisp
An overview of Java, Data types and variables
Imperative Data Structures
Allegro CL Certification Program
Perl I/O Learning Objectives:
Data Structures in Lisp
Data Structures in Lisp
Common Lisp II.
Procedures with optional parameters which do not require matching arguments Example: consider the exponent function which may take one argument, m, in.
Presentation transcript:

ANSI Common Lisp 4. Specialized Data Structures 7 June 2003

Array Make an array > (setf arr (make-array '(2 3) :initial- element nil)) Create an 2X3 array with initial values NIL. > (setf arr (make-array '(2 3) :initial- contents '((1 2 3) (4 5 6)))) Create an 2X3 array initialized with a sequence. By default, the elements can be of any type and the value of each element is undefined.

Array Retrieve array element >(aref arr 0 0) 1 Set array element > (setf (aref arr 0 0) 100) #2A(( ) (4 5 6)) Display an array *print-array* is t  #2A(( ) (4 5 6))

1-Dimensional Array (Vector) Make 1-D array > (setf vec (make-array 4 :initial-element nil)) > (setf vec (vector )) Retrieve array elements > (aref vec 0) > (svref vec 0) Vector is a type of CLISP type sequence, so sequence functions can be applied.

Characters A character c is denoted as #\c. Each character has an associated integer (generally, it’s ASCII number). char-code: returns the number associated with a character. code-char: returns the character associated with an integer. Comparison functions char, char>=, char/=

String String are vectors of characters. A constant string is surrounded by double-quotes. Since strings are vectors and a vector is an 1- dimensional array, so array functions work on strings. Since strings are vectors and vectors are sequences, so sequence functions work on strings too.

String Functions Building strings > (setf s (format nil "~A or ~A" "live free" "die")) "live free or die“ Join strings > (concatenate 'string "Go " "Will") "Go Will" String comparison functions

Sequences Sequence includes lists and vectors (and strings). Keyword arguments ParameterPurposeDefault :keyA function to apply to each element. identity :testThe test function for comparison.eql :from-endIf ture, work backwards.nil :startPosition at which to start.0 :endPosition at which to stop.nil

Sequences The remove-duplicates function > (remove-duplicates "abracadacra") "bdcra" Preserves the last occurrence of an element. The reduce function (reduce #’fn ‘(a b c d))  (fn (fn (fn ‘a ‘b) ‘c) ‘d) Extend functions that only take two arguments.

Example: Parsing Dates (defun tokens (str test start) (let ((p1 (position-if test str :start start))) (if p1 (let ((p2 (position-if #'(lambda (c) (not (funcall test c))) str :start p1))) (cons (subseq str p1 p2) (if p2 (tokens str test p2) nil))) nil)))

Example: Parsing Dates (defun constituent (c) (and (graphic-char-p c) (not (char= c #\ )))) The graphic characters are all characters we can see, plus the white space character.

Structures A simple definition (defstruct point x y) The make-point, point-p, copy-point, point-x and point-y functions are automatically generated. Create a new point (setf p (make-point :x 0 :y 0))

Structures Default values for structure fields (defstruct point (x 0) (y 0)) More controls (defstruct (point (:print-function print- point)) (x 0) (y 0)) (defun print-point (p stream depth) (format stream “ ” (point-x p) (point-y p)))

Hash Table Create a hash table (setf ht (make-hash-table)) Retrieve the value given a key (gethash ‘color ht) Associate a value with a key (setf (gethash ‘color ht) ‘red) Remove an entry (remhash ‘color ht)

Hash Table The maphash Function > (setf (gethash 'shape ht) 'spherical (gethash 'size ht) 'giant) GIANT > (maphash #'(lambda (k v) (format t "~A = ~A~%" k v)) ht) SIZE = GIANT SHAPE = SPHERICAL NIL