SlideShare a Scribd company logo
CSE240 – Introduction to
Programming Languages
Lecture 20:
Programming with LISP| Data Structures
Javier Gonzalez-Sanchez
javiergs@asu.edu
javiergs.engineering.asu.edu
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2
Data Structures
The only data structure is List
• (quote (hello world 1 2 3))
(HELLO WORLD 1 2 3)
• '(hello world 1 2 3)
(HELLO WORLD 1 2 3)
• (quote (what is (going on) here?))
(WHAT IS (GOING ON) HERE?)
• (quote my-symbol)
MY-SYMBOL
• (quote (+ 4 (* 3 2 9)))
(+ 4 (* 3 2 9))
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3
Data Structures
• first returns the first item in a list. The old name of first is car (content of
the address).
• rest returns a list consisting of everything but the first item. It does not
damage the original list. The old name of rest is cdr (content of the
decrement register).
• append hooks multiple lists together.
• cons takes an item and a list, and returns a new list consisting of the
old list with the item tacked on the front.
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4
Data Structures
• ( setf myList '( (A B) C (D) ) )
((A B) C (D))
• (car (car myList) ) ;( first ( first ) )
A
• (cdr( car myList)) ;( last ( first ) )
(B)
• (car (cdr myList)) ;( first ( rest ) )
C
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5
Data Structures
• ( setf myList2 '(A (B () (C () () )) (D (E () () ) () ) ) )
(A (B NIL (C NIL NIL)) (D (E NIL NIL) NIL))
• (car (car myList2)) ;( first ( first (L))
Error: Cannot take CAR of A.
• (cdr( car myList2)) ;( rest ( first (L))
Error: Cannot take CDR of A.
• (car (cdr myList2)) ;( first ( rest (L))
(B NIL (C NIL NIL))
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6
Loop (dolist)
• (dolist (x '(a b c d e)) (print x))
A
B
C
D
E
NIL
dolist is an iterator with this format
(dolist (var list-to-iterate-over optional-return-val)
expr1
expr2
…)
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7
Loop (dolist)
• (defun my-reverse (list)
(let (new-list) ; empty list
(dolist (x list)
(setf new-list (cons x new-list))
)
new-list)
)
MY-REVERSE
• (my-reverse '(a b c d e f g))
(G F E D C B A)
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8
Loop (dolist)
• (defun my-reverse (list)
(let (new-list) ; empty list
(dolist (x list)
(setf new-list (cons x new-list))
)
new-list)
)
MY-REVERSE
• (my-reverse '(a b c d e f g))
(G F E D C B A)
• (print (first (my-reverse '(a b c d e f g))))
G
• (print (last (my-reverse '(a b c d e f g))))
(A)
CSE240 – Introduction to Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Fall 2017
Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.

More Related Content

PPTX
La R Users Group Survey Of R Graphics
PDF
関数プログラマから見たPythonと機械学習
PPT
Clojure
PDF
201801 CSE240 Lecture 18
PDF
R 語言上手篇
PDF
Functional Programming
PDF
Beyond clicks dwell time for personalization
PPT
Tools for research plotting
La R Users Group Survey Of R Graphics
関数プログラマから見たPythonと機械学習
Clojure
201801 CSE240 Lecture 18
R 語言上手篇
Functional Programming
Beyond clicks dwell time for personalization
Tools for research plotting

What's hot (18)

PPT
Python 101 language features and functional programming
PPTX
Python Set.pptx
PDF
openCypher Technology Compatibility Kit (TCK)
PPTX
PPT
cloud computing training in chennai
PPT
6months industrial training in artificial intelligence, jalandhar
PPT
cloud computing training in delhi
PPT
6 weeks summer training in artificial intelligence,jalandhar
PPTX
Kotlin DSL beats the builder pattern
PPTX
Forms of Quadratics
KEY
ひけらかし会(visualization)
PDF
Recognize Godzilla
PPT
Bayesian learning
PDF
Geographic Information System (May – 2016) [75:25 Pattern | Question Paper]
PPTX
Visualization team presentation
PPTX
WF ED 540, Class Meeting 2 - Identifying & converting data types, 2016
PDF
[Question Paper] Computer Graphics (Revised Course) [June / 2016]
Python 101 language features and functional programming
Python Set.pptx
openCypher Technology Compatibility Kit (TCK)
cloud computing training in chennai
6months industrial training in artificial intelligence, jalandhar
cloud computing training in delhi
6 weeks summer training in artificial intelligence,jalandhar
Kotlin DSL beats the builder pattern
Forms of Quadratics
ひけらかし会(visualization)
Recognize Godzilla
Bayesian learning
Geographic Information System (May – 2016) [75:25 Pattern | Question Paper]
Visualization team presentation
WF ED 540, Class Meeting 2 - Identifying & converting data types, 2016
[Question Paper] Computer Graphics (Revised Course) [June / 2016]
Ad

Similar to 201801 CSE240 Lecture 20 (20)

PPT
Lisp, An Introduction.ppt
PPT
intro.ppt
PPT
intro.ppt
PDF
201801 CSE240 Lecture 17
PDF
The Functional Programming Triad of Map, Filter and Fold
PPTX
Functional Programming.pptx
RTF
Ex3 lisp likelist in java
PPT
Linked list introduction and different operation
PDF
L1 - Recap.pdf
PPTX
introduction_dst.pptx
PPTX
Linked List Data structure using C programming and all the detailed informat...
PPT
Data structures
PPT
recursion.ppt
PDF
201801 CSE240 Lecture 10
PPTX
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
PPTX
LISP: Introduction to lisp
PPTX
LISP: Introduction To Lisp
PDF
201801 CSE240 Lecture 09
PDF
Fjdkkdnncmckkgkhkhkkhkhkhkhkhkhkhkhkhkhhl
Lisp, An Introduction.ppt
intro.ppt
intro.ppt
201801 CSE240 Lecture 17
The Functional Programming Triad of Map, Filter and Fold
Functional Programming.pptx
Ex3 lisp likelist in java
Linked list introduction and different operation
L1 - Recap.pdf
introduction_dst.pptx
Linked List Data structure using C programming and all the detailed informat...
Data structures
recursion.ppt
201801 CSE240 Lecture 10
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
LISP: Introduction to lisp
LISP: Introduction To Lisp
201801 CSE240 Lecture 09
Fjdkkdnncmckkgkhkhkkhkhkhkhkhkhkhkhkhkhhl
Ad

More from Javier Gonzalez-Sanchez (20)

PDF
201804 SER332 Lecture 01
PDF
201801 SER332 Lecture 03
PDF
201801 SER332 Lecture 04
PDF
201801 SER332 Lecture 02
PDF
201801 CSE240 Lecture 26
PDF
201801 CSE240 Lecture 25
PDF
201801 CSE240 Lecture 24
PDF
201801 CSE240 Lecture 23
PDF
201801 CSE240 Lecture 22
PDF
201801 CSE240 Lecture 21
PDF
201801 CSE240 Lecture 19
PDF
201801 CSE240 Lecture 16
PDF
201801 CSE240 Lecture 15
PDF
201801 CSE240 Lecture 14
PDF
201801 CSE240 Lecture 13
PDF
201801 CSE240 Lecture 12
PDF
201801 CSE240 Lecture 11
PDF
201801 CSE240 Lecture 08
PDF
201801 CSE240 Lecture 07
PDF
201801 CSE240 Lecture 06
201804 SER332 Lecture 01
201801 SER332 Lecture 03
201801 SER332 Lecture 04
201801 SER332 Lecture 02
201801 CSE240 Lecture 26
201801 CSE240 Lecture 25
201801 CSE240 Lecture 24
201801 CSE240 Lecture 23
201801 CSE240 Lecture 22
201801 CSE240 Lecture 21
201801 CSE240 Lecture 19
201801 CSE240 Lecture 16
201801 CSE240 Lecture 15
201801 CSE240 Lecture 14
201801 CSE240 Lecture 13
201801 CSE240 Lecture 12
201801 CSE240 Lecture 11
201801 CSE240 Lecture 08
201801 CSE240 Lecture 07
201801 CSE240 Lecture 06

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
top salesforce developer skills in 2025.pdf
PDF
Nekopoi APK 2025 free lastest update
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
How Creative Agencies Leverage Project Management Software.pdf
Transform Your Business with a Software ERP System
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Odoo Companies in India – Driving Business Transformation.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Operating system designcfffgfgggggggvggggggggg
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
top salesforce developer skills in 2025.pdf
Nekopoi APK 2025 free lastest update
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

201801 CSE240 Lecture 20

  • 1. CSE240 – Introduction to Programming Languages Lecture 20: Programming with LISP| Data Structures Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2 Data Structures The only data structure is List • (quote (hello world 1 2 3)) (HELLO WORLD 1 2 3) • '(hello world 1 2 3) (HELLO WORLD 1 2 3) • (quote (what is (going on) here?)) (WHAT IS (GOING ON) HERE?) • (quote my-symbol) MY-SYMBOL • (quote (+ 4 (* 3 2 9))) (+ 4 (* 3 2 9))
  • 3. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3 Data Structures • first returns the first item in a list. The old name of first is car (content of the address). • rest returns a list consisting of everything but the first item. It does not damage the original list. The old name of rest is cdr (content of the decrement register). • append hooks multiple lists together. • cons takes an item and a list, and returns a new list consisting of the old list with the item tacked on the front.
  • 4. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4 Data Structures • ( setf myList '( (A B) C (D) ) ) ((A B) C (D)) • (car (car myList) ) ;( first ( first ) ) A • (cdr( car myList)) ;( last ( first ) ) (B) • (car (cdr myList)) ;( first ( rest ) ) C
  • 5. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5 Data Structures • ( setf myList2 '(A (B () (C () () )) (D (E () () ) () ) ) ) (A (B NIL (C NIL NIL)) (D (E NIL NIL) NIL)) • (car (car myList2)) ;( first ( first (L)) Error: Cannot take CAR of A. • (cdr( car myList2)) ;( rest ( first (L)) Error: Cannot take CDR of A. • (car (cdr myList2)) ;( first ( rest (L)) (B NIL (C NIL NIL))
  • 6. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6 Loop (dolist) • (dolist (x '(a b c d e)) (print x)) A B C D E NIL dolist is an iterator with this format (dolist (var list-to-iterate-over optional-return-val) expr1 expr2 …)
  • 7. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7 Loop (dolist) • (defun my-reverse (list) (let (new-list) ; empty list (dolist (x list) (setf new-list (cons x new-list)) ) new-list) ) MY-REVERSE • (my-reverse '(a b c d e f g)) (G F E D C B A)
  • 8. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8 Loop (dolist) • (defun my-reverse (list) (let (new-list) ; empty list (dolist (x list) (setf new-list (cons x new-list)) ) new-list) ) MY-REVERSE • (my-reverse '(a b c d e f g)) (G F E D C B A) • (print (first (my-reverse '(a b c d e f g)))) G • (print (last (my-reverse '(a b c d e f g)))) (A)
  • 9. CSE240 – Introduction to Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Fall 2017 Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.