2
Most read
5
Most read
9
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

PPT
INTRODUCTION TO LISP
PPTX
LISP: Introduction to lisp
PPTX
Finite automata-for-lexical-analysis
PPTX
Syntax Analysis in Compiler Design
PPTX
Lexical Analysis - Compiler Design
PPTX
Introduction TO Finite Automata
PPTX
INTRODUCTION TO LISP
LISP: Introduction to lisp
Finite automata-for-lexical-analysis
Syntax Analysis in Compiler Design
Lexical Analysis - Compiler Design
Introduction TO Finite Automata

What's hot (20)

PPTX
Lexical analysis - Compiler Design
PPTX
CONTEXT FREE GRAMMAR
PPTX
Input-Buffering
PPT
Complexity of Algorithm
PPTX
Context free grammar
PDF
Parse Tree
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PDF
Syntax analysis
PDF
Syntax directed translation
PDF
Lecture Notes-Finite State Automata for NLP.pdf
PPT
Parsing
PPT
Lecture 1,2
PPTX
Data Structures : hashing (1)
PPTX
Regular Expression (Regex) Fundamentals
PPT
Regular Languages
PPT
1.Role lexical Analyzer
PPSX
PDF
Lecture: Context-Free Grammars
PPTX
Asymptotic Notation
PPTX
Finite Automata in compiler design
Lexical analysis - Compiler Design
CONTEXT FREE GRAMMAR
Input-Buffering
Complexity of Algorithm
Context free grammar
Parse Tree
Type Checking(Compiler Design) #ShareThisIfYouLike
Syntax analysis
Syntax directed translation
Lecture Notes-Finite State Automata for NLP.pdf
Parsing
Lecture 1,2
Data Structures : hashing (1)
Regular Expression (Regex) Fundamentals
Regular Languages
1.Role lexical Analyzer
Lecture: Context-Free Grammars
Asymptotic Notation
Finite Automata in compiler design
Ad

Similar to Introduction to Programming in LISP (20)

PPT
Designing A Syntax Based Retrieval System03
PPTX
Report about the LISP Programming Language
PPTX
Principles of programming language intro
PPT
operators and arithmatic expression in C Language
PPTX
8. Functional Programming_updated(1).pptx
PPTX
AI UNIT-4 Final (2).pptx
PPTX
LISP: Introduction To Lisp
PPTX
A brief introduction to lisp language
PDF
Basics of Functional Programming
ODP
Functions & Closures in Scala
ODP
Functions & closures
ODP
Functions & Closures in Scala
PPTX
PPT
Introduction to lambda calculus
PPTX
UNIT – 3.pptx for first year engineering
PPTX
OOPS Object oriented Programming PPT Tutorial
PPT
Lisp and scheme i
PPTX
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
PDF
Programming in Scala - Lecture Two
PPTX
UNIT-02-pythonfunctions python function using detehdjsjehhdjejdhdjdjdjddjdhdhhd
Designing A Syntax Based Retrieval System03
Report about the LISP Programming Language
Principles of programming language intro
operators and arithmatic expression in C Language
8. Functional Programming_updated(1).pptx
AI UNIT-4 Final (2).pptx
LISP: Introduction To Lisp
A brief introduction to lisp language
Basics of Functional Programming
Functions & Closures in Scala
Functions & closures
Functions & Closures in Scala
Introduction to lambda calculus
UNIT – 3.pptx for first year engineering
OOPS Object oriented Programming PPT Tutorial
Lisp and scheme i
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
Programming in Scala - Lecture Two
UNIT-02-pythonfunctions python function using detehdjsjehhdjejdhdjdjdjddjdhdhhd
Ad

More from Knoldus Inc. (20)

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

Recently uploaded (20)

PDF
AI Guide for Business Growth - Arna Softech
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PPTX
Computer Software - Technology and Livelihood Education
PDF
Microsoft Office 365 Crack Download Free
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PPTX
Download Adobe Photoshop Crack 2025 Free
PDF
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PPTX
Cybersecurity: Protecting the Digital World
PDF
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
PPTX
Introduction to Windows Operating System
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
E-Commerce Website Development Companyin india
PDF
Guide to Food Delivery App Development.pdf
PPTX
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
PPTX
Lecture 5 Software Requirement Engineering
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
AI Guide for Business Growth - Arna Softech
Wondershare Recoverit Full Crack New Version (Latest 2025)
Computer Software - Technology and Livelihood Education
Microsoft Office 365 Crack Download Free
GSA Content Generator Crack (2025 Latest)
CCleaner 6.39.11548 Crack 2025 License Key
Download Adobe Photoshop Crack 2025 Free
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
BoxLang Dynamic AWS Lambda - Japan Edition
iTop VPN Crack Latest Version Full Key 2025
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
Cybersecurity: Protecting the Digital World
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
Introduction to Windows Operating System
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
E-Commerce Website Development Companyin india
Guide to Food Delivery App Development.pdf
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
Lecture 5 Software Requirement Engineering
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业

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)