SlideShare a Scribd company logo
1 of 9
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

What's hot

Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)openCypher
 
cloud computing training in chennai
cloud computing training in chennaicloud computing training in chennai
cloud computing training in chennaimatrixphagwara
 
6months industrial training in artificial intelligence, jalandhar
6months industrial training in artificial intelligence, jalandhar6months industrial training in artificial intelligence, jalandhar
6months industrial training in artificial intelligence, jalandhardeepikakaler1
 
cloud computing training in delhi
cloud computing training in delhicloud computing training in delhi
cloud computing training in delhimatrixphagwara
 
6 weeks summer training in artificial intelligence,jalandhar
6 weeks summer training in artificial intelligence,jalandhar6 weeks summer training in artificial intelligence,jalandhar
6 weeks summer training in artificial intelligence,jalandhardeepikakaler1
 
Kotlin DSL beats the builder pattern
Kotlin DSL beats the builder patternKotlin DSL beats the builder pattern
Kotlin DSL beats the builder patternarild2
 
Forms of Quadratics
Forms of QuadraticsForms of Quadratics
Forms of Quadraticsmrodolewicz
 
ひけらかし会(visualization)
ひけらかし会(visualization)ひけらかし会(visualization)
ひけらかし会(visualization)moai kids
 
Bayesian learning
Bayesian learning Bayesian learning
Bayesian learning EngReads
 
Geographic Information System (May – 2016) [75:25 Pattern | Question Paper]
Geographic Information System (May – 2016) [75:25 Pattern | Question Paper]Geographic Information System (May – 2016) [75:25 Pattern | Question Paper]
Geographic Information System (May – 2016) [75:25 Pattern | Question Paper]Mumbai B.Sc.IT Study
 
Visualization team presentation
Visualization team presentation Visualization team presentation
Visualization team presentation madhobilota
 
WF ED 540, Class Meeting 2 - Identifying & converting data types, 2016
WF ED 540, Class Meeting 2 - Identifying & converting data types, 2016WF ED 540, Class Meeting 2 - Identifying & converting data types, 2016
WF ED 540, Class Meeting 2 - Identifying & converting data types, 2016Penn State University
 
[Question Paper] Computer Graphics (Revised Course) [June / 2016]
[Question Paper] Computer Graphics (Revised Course) [June / 2016][Question Paper] Computer Graphics (Revised Course) [June / 2016]
[Question Paper] Computer Graphics (Revised Course) [June / 2016]Mumbai B.Sc.IT Study
 

What's hot (18)

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

Similar to 201801 CSE240 Lecture 20

Recursion and Functional Programming
Recursion and Functional ProgrammingRecursion and Functional Programming
Recursion and Functional Programmingsathish316
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) wahab khan
 
Microsoft Word Practice Exercise Set 2
Microsoft Word   Practice Exercise Set 2Microsoft Word   Practice Exercise Set 2
Microsoft Word Practice Exercise Set 2rampan
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojureRoy Rutto
 
Add math may june 2016 p1
Add math may june 2016 p1Add math may june 2016 p1
Add math may june 2016 p1Don Cunningham
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lispkyleburton
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with RShareThis
 
Lisp tutorial
Lisp tutorialLisp tutorial
Lisp tutorialNilt1234
 
[Paper Reading] Generalized Sub-Query Fusion for Eliminating Redundant I/O fr...
[Paper Reading] Generalized Sub-Query Fusion for Eliminating Redundant I/O fr...[Paper Reading] Generalized Sub-Query Fusion for Eliminating Redundant I/O fr...
[Paper Reading] Generalized Sub-Query Fusion for Eliminating Redundant I/O fr...PingCAP
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptxPremBorse1
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 

Similar to 201801 CSE240 Lecture 20 (20)

201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
Recursion and Functional Programming
Recursion and Functional ProgrammingRecursion and Functional Programming
Recursion and Functional Programming
 
Scheme 核心概念(一)
Scheme 核心概念(一)Scheme 核心概念(一)
Scheme 核心概念(一)
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
 
Scheme language
Scheme languageScheme language
Scheme language
 
Microsoft Word Practice Exercise Set 2
Microsoft Word   Practice Exercise Set 2Microsoft Word   Practice Exercise Set 2
Microsoft Word Practice Exercise Set 2
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojure
 
Add math may june 2016 p1
Add math may june 2016 p1Add math may june 2016 p1
Add math may june 2016 p1
 
Perm winter school 2014.01.31
Perm winter school 2014.01.31Perm winter school 2014.01.31
Perm winter school 2014.01.31
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
Data analysis with R
Data analysis with RData analysis with R
Data analysis with R
 
Lisp tutorial
Lisp tutorialLisp tutorial
Lisp tutorial
 
Ada
AdaAda
Ada
 
[Paper Reading] Generalized Sub-Query Fusion for Eliminating Redundant I/O fr...
[Paper Reading] Generalized Sub-Query Fusion for Eliminating Redundant I/O fr...[Paper Reading] Generalized Sub-Query Fusion for Eliminating Redundant I/O fr...
[Paper Reading] Generalized Sub-Query Fusion for Eliminating Redundant I/O fr...
 
dld 01-introduction
dld 01-introductiondld 01-introduction
dld 01-introduction
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 
201801 CSE240 Lecture 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
 
201801 CSE240 Lecture 09
201801 CSE240 Lecture 09201801 CSE240 Lecture 09
201801 CSE240 Lecture 09
 
201801 CSE240 Lecture 08
201801 CSE240 Lecture 08201801 CSE240 Lecture 08
201801 CSE240 Lecture 08
 

Recently uploaded

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

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.