SlideShare a Scribd company logo
3
Most read
4
Most read
8
Most read
Introduction to Programming in
LISP
...
Akash Sethi
Software Consultant
Knoldus Software LLP.
Agenda
โ— Why LISP
โ— What is LISP
โ— Timeline of Lisp dialects
โ— Fundamentals of LISP
โ— Expression Evaluation in LISP
โ— Defining Variables
โ— Evaluating Combinations
โ— Procedure Definitions
โ— The Substitution Model for Procedure Application
โ— Conditional Expressions
โ— Linear Recursion and Iteration
Why LISP
The Key motivations behind Learning LISP are as follow:-
โ— Some of the features of Scala are inherited from LISP.
โ— Scala is Hybrid Programming Language. It consist features of both
Functional and Object Oriented Programming Language.
โ— We most of us know the Object Oriented programming Language like JAVA,
C++ etc.
โ— Undersanding the Basics of LISP can help us understand the other
functional programming languages like clojure.
What is LISP
โ— LISP, an acronym for list processing, is a programming language that was
designed for easy manipulation of data strings.
โ— Developed in 1959 by John McCarthy,
โ— It is a commonly used language for artificial intelligence (AI) programming.
โ— It is one of the oldest programming languages still in relatively wide use.
โ— All program code is written as s-expressions, or parenthesized lists.
Timeline of Lisp dialects
What is LISP
โ— LISP, an acronym for list processing, is a programming language that was
designed for easy manipulation of data strings.
โ— Developed in 1959 by John McCarthy,
โ— It is a commonly used language for artificial intelligence (AI) programming.
โ— It is one of the oldest programming languages still in relatively wide use.
โ— All program code is written as s-expressions, or parenthesized lists.
Fundamentals of LISP
Every powerful language has three mechanisms for accomplishing this :-
โ— Primitive expressions, which represent the simplest entities the language
is concerned with,
โ— Means of combination, by which compound elements are built from
simpler ones, and
โ— Means of abstraction, by which compound elements can be named and
manipulated as units.
Expression Evaluation in LISP
Expressions representing numbers may be combined with an expression representing a
primitive procedure (such as + or *) to form a compound expression that represents the
application of the procedure to those numbers. For example:-
(+ 137 349)
486
(- 1000 334)
666
(* 5 99)
495
(/ 10 5)
2
Expression Evaluation in LISP
Expressions such as these, formed by delimiting a list of expressions within
parentheses in order to denote procedure application, are called combinations.
โ— The leftmost element in the list is called the operator, and the other elements are
called operands.
โ— The value of a combination is obtained by applying the procedure specified by the
operator to the arguments that are the values of the operands.
โ— The convention of placing the operator to the left of the operands is known as
prefix notation.
โ— No ambiguity can arise, because the operator is always the leftmost element and
the entire combination is delimited by the parentheses.
Defining Variables
Define is LISP language's simplest means of abstraction, for it allows us to
use simple names to refer to the results of compound operation.
(define pi 3.14159)
(define radius 10)
(* pi (* radius radius))
314.159
(define circumference (* 2 pi radius))
Circumference
62.8318
Evaluating Combinations
To evaluate a combination, do the following:
โ— 1. Evaluate the subexpressions of the combination.
โ— 2. Apply the procedure that is the
value of the leftmost subexpression
(the operator) to the arguments
that are the values of the other
subexpressions (the operands).
(* (+ 2 (* 4 6))
(+ 3 5 7))
Evaluating Combinations
Each combination is represented by a node with branches corresponding to the
operator and the operands of the combination stemming from it.
The terminal nodes (that is, nodes with no branches stemming from them)
represent either operators or numbers. Viewing evaluation in terms of the tree,
we can imagine that the values of the operands percolate upward, starting from
the terminal nodes and then combining at higher and higher levels.
the ``percolate values upward'' form of the evaluation rule is an example of a
general kind of process known as tree accumulation.
Procedure Definitions
A much more powerful abstraction technique by which a compound operation can
be given a name and then referred to as a unit.
(define (square x) (* x x))
We can understand this in the following way:
(define (square x) (* x x))
square something, multiply it by itself.
We have here a compound procedure, which has been given the name square. The
procedure represents the operation of multiplying something by itself. The thing to
be multiplied is given a local name, x, which plays the same role that a pronoun
plays in natural language. Evaluating the definition creates this compound
procedure and associates it with the name square
The Substitution Model for Procedure Application
There Exists 2 type of Orders to Evaluate any Procedure in LISP.
โ— Normal Order
โ— Applicative Order
โ— Normal Order :- the interpreter first evaluates the operator and operands
and then applies the resulting procedure to the resulting arguments
Normal Order
Normal Order Example :-
(sum-of-squares (+ 5 1) (* 5 2))
(+ (square 6) (square 10 ) )
If we use the definition of square, this reduces to
(+ (* 6 6) (* 10 10))
which reduces by multiplication to
(+ 36 100)
and finally to
136
Applicative Order
โ— Applicative Order :- An alternative evaluation model would not evaluate the operands until their
values were needed. Instead it would first substitute operand expressions for parameters until it
obtained an expression involving only primitive operators, and would then perform the evaluation.
(sum-of-squares (+ 5 1) (* 5 2))
(+ (square (+ 5 1)) (square (* 5 2)) )
(+ (* (+ 5 1) (+ 5 1)) (* (* 5 2) (* 5 2)))
followed by the reductions
(+ (* 6 6) (* 10 10))
(+ 36 100)
136
Conditional Expressions
Most of the time situation arises when we need to perform some operation based on
some condition.
For Example :- Finding the Absolute value.
Condition will be :-
โ— IF x > 0 return x
IF x = 0 return 0
IF x < 0 return -x
This construct is called a case analysis, and there is a special form in Lisp for notating such
a case analysis. It is called cond (which stands for โ€˜โ€˜conditionalโ€™โ€™), and it is used as follows:
โ— (define (abs x)
(cond ((> x 0) x)
((= x 0) 0)
((< x 0) (- x))))
Linear Recursion and Iteration
โ— Recursion:- the repeated application of a recursive procedure or definition.
โ— Iteration:- the repetition of a process.
Example:- Finding the Factorial of some number.This can easily implemented in 2
ways .
โ— Using Recusrion
โ— Using Iteration.
Linear Recursion
โ— Factorial Using the Recursion in LISP
(define (factorial n)
(if (= n 1)
1
(* n (factorial (- n 1)))))
โ— Here, Time Complexity is O(x)
โ— Space Complexity is O(x)
Linear Recursion
Iteration
โ— Factorial Using the Iteration in LISP
(define (factorial n)
(fact-iter 1 1 n))
(define (fact-iter product counter max-count)
(if (> counter max-count)
product
(fact-iter (* counter product)
(+ counter 1)
max-count)))
โ— Here, Time Complexity is O(x)
โ— Space Complexity is O(1)
Iteration
References
โ— http://mitpress.mit.edu/sicp/
Thank You

More Related Content

What's hot (20)

PPTX
Lisp
sonukumar142
ย 
PPTX
Asymptotic notations
Nikhil Sharma
ย 
PPTX
Stressen's matrix multiplication
Kumar
ย 
PPT
Bottom - Up Parsing
kunj desai
ย 
PPTX
Greedy Algorithms
Amrinder Arora
ย 
PPT
Data Structure and Algorithms Hashing
ManishPrajapati78
ย 
PPTX
AI Programming language (LISP)
Dr. SURBHI SAROHA
ย 
PPT
Sum of subsets problem by backtrackingย 
Hasanain Alshadoodee
ย 
PPTX
Topological Sorting
ShahDhruv21
ย 
PDF
Deterministic Finite Automata (DFA)
Animesh Chaturvedi
ย 
PPTX
Graphs in data structure
hamza javed
ย 
PDF
Lecture Notes-Finite State Automata for NLP.pdf
Deptii Chaudhari
ย 
PDF
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
ย 
PPTX
Array Of Pointers
Sharad Dubey
ย 
PPT
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
ย 
PPTX
Planning
Amar Jukuntla
ย 
PPTX
Bruteforce algorithm
Rezwan Siam
ย 
PPTX
Python in 30 minutes!
Fariz Darari
ย 
PPT
Red black tree
Rajendran
ย 
Lisp
sonukumar142
ย 
Asymptotic notations
Nikhil Sharma
ย 
Stressen's matrix multiplication
Kumar
ย 
Bottom - Up Parsing
kunj desai
ย 
Greedy Algorithms
Amrinder Arora
ย 
Data Structure and Algorithms Hashing
ManishPrajapati78
ย 
AI Programming language (LISP)
Dr. SURBHI SAROHA
ย 
Sum of subsets problem by backtrackingย 
Hasanain Alshadoodee
ย 
Topological Sorting
ShahDhruv21
ย 
Deterministic Finite Automata (DFA)
Animesh Chaturvedi
ย 
Graphs in data structure
hamza javed
ย 
Lecture Notes-Finite State Automata for NLP.pdf
Deptii Chaudhari
ย 
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
ย 
Array Of Pointers
Sharad Dubey
ย 
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
ย 
Planning
Amar Jukuntla
ย 
Bruteforce algorithm
Rezwan Siam
ย 
Python in 30 minutes!
Fariz Darari
ย 
Red black tree
Rajendran
ย 

Similar to Introduction to Programming in LISP (20)

PPT
Designing A Syntax Based Retrieval System03
Avelin Huo
ย 
PPT
INTRODUCTION TO LISP
Nilt1234
ย 
PPTX
Report about the LISP Programming Language
maldosmelandrew
ย 
PPTX
Principles of programming language intro
RajeswariA8
ย 
PPT
operators and arithmatic expression in C Language
ParamesswariNataraja
ย 
PPTX
8. Functional Programming_updated(1).pptx
jaymalachavan
ย 
PPTX
AI UNIT-4 Final (2).pptx
prakashvs7
ย 
PPTX
LISP: Introduction to lisp
DataminingTools Inc
ย 
PPTX
LISP: Introduction To Lisp
LISP Content
ย 
PPTX
A brief introduction to lisp language
David Gu
ย 
PDF
Basics of Functional Programming
Sartaj Singh
ย 
ODP
Functions & Closures in Scala
Knoldus Inc.
ย 
ODP
Functions & Closures in Scala
Neelkanth Sachdeva
ย 
ODP
Functions & closures
Knoldus Inc.
ย 
PPTX
Lisp
huzaifa ramzan
ย 
PPT
Introduction to lambda calculus
Afaq Siddiqui
ย 
PPTX
UNIT โ€“ 3.pptx for first year engineering
SabarigiriVason
ย 
PPTX
OOPS Object oriented Programming PPT Tutorial
amitnitpatna
ย 
PPT
Lisp and scheme i
Luis Goldster
ย 
PPTX
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
kamalsmail1
ย 
Designing A Syntax Based Retrieval System03
Avelin Huo
ย 
INTRODUCTION TO LISP
Nilt1234
ย 
Report about the LISP Programming Language
maldosmelandrew
ย 
Principles of programming language intro
RajeswariA8
ย 
operators and arithmatic expression in C Language
ParamesswariNataraja
ย 
8. Functional Programming_updated(1).pptx
jaymalachavan
ย 
AI UNIT-4 Final (2).pptx
prakashvs7
ย 
LISP: Introduction to lisp
DataminingTools Inc
ย 
LISP: Introduction To Lisp
LISP Content
ย 
A brief introduction to lisp language
David Gu
ย 
Basics of Functional Programming
Sartaj Singh
ย 
Functions & Closures in Scala
Knoldus Inc.
ย 
Functions & Closures in Scala
Neelkanth Sachdeva
ย 
Functions & closures
Knoldus Inc.
ย 
Introduction to lambda calculus
Afaq Siddiqui
ย 
UNIT โ€“ 3.pptx for first year engineering
SabarigiriVason
ย 
OOPS Object oriented Programming PPT Tutorial
amitnitpatna
ย 
Lisp and scheme i
Luis Goldster
ย 
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
kamalsmail1
ย 
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
ย 
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
ย 
PPTX
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
ย 
PPTX
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
ย 
PPTX
Java 17 features and implementation.pptx
Knoldus Inc.
ย 
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
ย 
PPTX
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
ย 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
ย 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
ย 
PPTX
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
ย 
PPTX
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
ย 
PPTX
Introduction to Argo Rollouts Presentation
Knoldus Inc.
ย 
PPTX
Intro to Azure Container App Presentation
Knoldus Inc.
ย 
PPTX
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
ย 
PPTX
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
ย 
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
ย 
PPTX
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
ย 
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
ย 
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
ย 
PPTX
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
ย 
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
ย 
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
ย 
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
ย 
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
ย 
Java 17 features and implementation.pptx
Knoldus Inc.
ย 
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
ย 
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
ย 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
ย 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
ย 
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
ย 
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
ย 
Introduction to Argo Rollouts Presentation
Knoldus Inc.
ย 
Intro to Azure Container App Presentation
Knoldus Inc.
ย 
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
ย 
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
ย 
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
ย 
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
ย 
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
ย 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
ย 
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
ย 
Ad

Recently uploaded (20)

PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
ย 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
PPTX
Introduction to web development | MERN Stack
JosephLiyon
ย 
PPTX
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
ย 
PDF
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
ย 
PPTX
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
ย 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
ย 
PDF
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
ย 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
ย 
PDF
Dealing with JSON in the relational world
Andres Almiray
ย 
PDF
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
PPTX
Avast Premium Security crack 25.5.6162 + License Key 2025
HyperPc soft
ย 
PDF
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
ย 
PDF
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
ย 
PDF
Automated Test Case Repair Using Language Models
Lionel Briand
ย 
PDF
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
ย 
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
PDF
>Wondershare Filmora Crack Free Download 2025
utfefguu
ย 
PDF
Building scalbale cloud native apps with .NET 8
GillesMathieu10
ย 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
ย 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
Introduction to web development | MERN Stack
JosephLiyon
ย 
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
ย 
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
ย 
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
ย 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
ย 
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
ย 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
ย 
Dealing with JSON in the relational world
Andres Almiray
ย 
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
Avast Premium Security crack 25.5.6162 + License Key 2025
HyperPc soft
ย 
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
ย 
TEASMA: A Practical Methodology for Test Adequacy Assessment of Deep Neural N...
Lionel Briand
ย 
Automated Test Case Repair Using Language Models
Lionel Briand
ย 
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
ย 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
>Wondershare Filmora Crack Free Download 2025
utfefguu
ย 
Building scalbale cloud native apps with .NET 8
GillesMathieu10
ย 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 

Introduction to Programming in LISP

  • 1. Introduction to Programming in LISP ... Akash Sethi Software Consultant Knoldus Software LLP.
  • 2. Agenda โ— Why LISP โ— What is LISP โ— Timeline of Lisp dialects โ— Fundamentals of LISP โ— Expression Evaluation in LISP โ— Defining Variables โ— Evaluating Combinations โ— Procedure Definitions โ— The Substitution Model for Procedure Application โ— Conditional Expressions โ— Linear Recursion and Iteration
  • 3. Why LISP The Key motivations behind Learning LISP are as follow:- โ— Some of the features of Scala are inherited from LISP. โ— Scala is Hybrid Programming Language. It consist features of both Functional and Object Oriented Programming Language. โ— We most of us know the Object Oriented programming Language like JAVA, C++ etc. โ— Undersanding the Basics of LISP can help us understand the other functional programming languages like clojure.
  • 4. What is LISP โ— LISP, an acronym for list processing, is a programming language that was designed for easy manipulation of data strings. โ— Developed in 1959 by John McCarthy, โ— It is a commonly used language for artificial intelligence (AI) programming. โ— It is one of the oldest programming languages still in relatively wide use. โ— All program code is written as s-expressions, or parenthesized lists.
  • 5. Timeline of Lisp dialects
  • 6. What is LISP โ— LISP, an acronym for list processing, is a programming language that was designed for easy manipulation of data strings. โ— Developed in 1959 by John McCarthy, โ— It is a commonly used language for artificial intelligence (AI) programming. โ— It is one of the oldest programming languages still in relatively wide use. โ— All program code is written as s-expressions, or parenthesized lists.
  • 7. Fundamentals of LISP Every powerful language has three mechanisms for accomplishing this :- โ— Primitive expressions, which represent the simplest entities the language is concerned with, โ— Means of combination, by which compound elements are built from simpler ones, and โ— Means of abstraction, by which compound elements can be named and manipulated as units.
  • 8. Expression Evaluation in LISP Expressions representing numbers may be combined with an expression representing a primitive procedure (such as + or *) to form a compound expression that represents the application of the procedure to those numbers. For example:- (+ 137 349) 486 (- 1000 334) 666 (* 5 99) 495 (/ 10 5) 2
  • 9. Expression Evaluation in LISP Expressions such as these, formed by delimiting a list of expressions within parentheses in order to denote procedure application, are called combinations. โ— The leftmost element in the list is called the operator, and the other elements are called operands. โ— The value of a combination is obtained by applying the procedure specified by the operator to the arguments that are the values of the operands. โ— The convention of placing the operator to the left of the operands is known as prefix notation. โ— No ambiguity can arise, because the operator is always the leftmost element and the entire combination is delimited by the parentheses.
  • 10. Defining Variables Define is LISP language's simplest means of abstraction, for it allows us to use simple names to refer to the results of compound operation. (define pi 3.14159) (define radius 10) (* pi (* radius radius)) 314.159 (define circumference (* 2 pi radius)) Circumference 62.8318
  • 11. Evaluating Combinations To evaluate a combination, do the following: โ— 1. Evaluate the subexpressions of the combination. โ— 2. Apply the procedure that is the value of the leftmost subexpression (the operator) to the arguments that are the values of the other subexpressions (the operands). (* (+ 2 (* 4 6)) (+ 3 5 7))
  • 12. Evaluating Combinations Each combination is represented by a node with branches corresponding to the operator and the operands of the combination stemming from it. The terminal nodes (that is, nodes with no branches stemming from them) represent either operators or numbers. Viewing evaluation in terms of the tree, we can imagine that the values of the operands percolate upward, starting from the terminal nodes and then combining at higher and higher levels. the ``percolate values upward'' form of the evaluation rule is an example of a general kind of process known as tree accumulation.
  • 13. Procedure Definitions A much more powerful abstraction technique by which a compound operation can be given a name and then referred to as a unit. (define (square x) (* x x)) We can understand this in the following way: (define (square x) (* x x)) square something, multiply it by itself. We have here a compound procedure, which has been given the name square. The procedure represents the operation of multiplying something by itself. The thing to be multiplied is given a local name, x, which plays the same role that a pronoun plays in natural language. Evaluating the definition creates this compound procedure and associates it with the name square
  • 14. The Substitution Model for Procedure Application There Exists 2 type of Orders to Evaluate any Procedure in LISP. โ— Normal Order โ— Applicative Order โ— Normal Order :- the interpreter first evaluates the operator and operands and then applies the resulting procedure to the resulting arguments
  • 15. Normal Order Normal Order Example :- (sum-of-squares (+ 5 1) (* 5 2)) (+ (square 6) (square 10 ) ) If we use the definition of square, this reduces to (+ (* 6 6) (* 10 10)) which reduces by multiplication to (+ 36 100) and finally to 136
  • 16. Applicative Order โ— Applicative Order :- An alternative evaluation model would not evaluate the operands until their values were needed. Instead it would first substitute operand expressions for parameters until it obtained an expression involving only primitive operators, and would then perform the evaluation. (sum-of-squares (+ 5 1) (* 5 2)) (+ (square (+ 5 1)) (square (* 5 2)) ) (+ (* (+ 5 1) (+ 5 1)) (* (* 5 2) (* 5 2))) followed by the reductions (+ (* 6 6) (* 10 10)) (+ 36 100) 136
  • 17. Conditional Expressions Most of the time situation arises when we need to perform some operation based on some condition. For Example :- Finding the Absolute value. Condition will be :- โ— IF x > 0 return x IF x = 0 return 0 IF x < 0 return -x This construct is called a case analysis, and there is a special form in Lisp for notating such a case analysis. It is called cond (which stands for โ€˜โ€˜conditionalโ€™โ€™), and it is used as follows: โ— (define (abs x) (cond ((> x 0) x) ((= x 0) 0) ((< x 0) (- x))))
  • 18. Linear Recursion and Iteration โ— Recursion:- the repeated application of a recursive procedure or definition. โ— Iteration:- the repetition of a process. Example:- Finding the Factorial of some number.This can easily implemented in 2 ways . โ— Using Recusrion โ— Using Iteration.
  • 19. Linear Recursion โ— Factorial Using the Recursion in LISP (define (factorial n) (if (= n 1) 1 (* n (factorial (- n 1))))) โ— Here, Time Complexity is O(x) โ— Space Complexity is O(x)
  • 21. Iteration โ— Factorial Using the Iteration in LISP (define (factorial n) (fact-iter 1 1 n)) (define (fact-iter product counter max-count) (if (> counter max-count) product (fact-iter (* counter product) (+ counter 1) max-count))) โ— Here, Time Complexity is O(x) โ— Space Complexity is O(1)