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

Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
Bipul Roy Bpl
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
RaginiJain21
 
Lisp
LispLisp
Bubble sort
Bubble sortBubble sort
Bubble sort
Manek Ar
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
Prof. Dr. K. Adisesha
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
Rushdi Shams
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
Mohammed Sikander
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
Megha Sharma
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
Eelco Visser
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
Shubham Dwivedi
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
Akhil Kaushik
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
Arun Sial
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
Dr Shashikant Athawale
 
Introduction to CLIPS Expert System
Introduction to CLIPS Expert SystemIntroduction to CLIPS Expert System
Introduction to CLIPS Expert System
Motaz Saad
 

What's hot (20)

Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Lisp
LispLisp
Lisp
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Event handling
Event handlingEvent handling
Event handling
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Introduction to CLIPS Expert System
Introduction to CLIPS Expert SystemIntroduction to CLIPS Expert System
Introduction to CLIPS Expert System
 

Similar to Introduction to Programming in LISP

Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Avelin Huo
 
AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptx
prakashvs7
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
 
Lisp
LispLisp
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Basics of Functional Programming
Basics of Functional ProgrammingBasics of Functional Programming
Basics of Functional Programming
Sartaj Singh
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
Knoldus Inc.
 
Functions & Closures in Scala
Functions & Closures in ScalaFunctions & Closures in Scala
Functions & Closures in Scala
Knoldus Inc.
 
Functions & Closures in Scala
Functions & Closures in ScalaFunctions & Closures in Scala
Functions & Closures in Scala
Neelkanth Sachdeva
 
Introduction to lambda calculus
Introduction to lambda calculusIntroduction to lambda calculus
Introduction to lambda calculus
Afaq Siddiqui
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
Luis Goldster
 
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkkExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
kamalsmail1
 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
Angelo Corsaro
 
E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)Mukund Trivedi
 
E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)Mukund Trivedi
 
E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2Mukund Trivedi
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
KarthickT28
 
Although people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxAlthough people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docx
milissaccm
 
Java 8
Java 8Java 8
Java 8
vilniusjug
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
abhi353063
 

Similar to Introduction to Programming in LISP (20)

Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
 
AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptx
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 
Lisp
LispLisp
Lisp
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
Basics of Functional Programming
Basics of Functional ProgrammingBasics of Functional Programming
Basics of Functional Programming
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
 
Functions & Closures in Scala
Functions & Closures in ScalaFunctions & Closures in Scala
Functions & Closures in Scala
 
Functions & Closures in Scala
Functions & Closures in ScalaFunctions & Closures in Scala
Functions & Closures in Scala
 
Introduction to lambda calculus
Introduction to lambda calculusIntroduction to lambda calculus
Introduction to lambda calculus
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
 
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkkExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
 
E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)
 
E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)
 
E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
Although people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxAlthough people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docx
 
Java 8
Java 8Java 8
Java 8
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
 

More from Knoldus Inc.

Getting Started with Apache Spark (Scala)
Getting Started with Apache Spark (Scala)Getting Started with Apache Spark (Scala)
Getting Started with Apache Spark (Scala)
Knoldus Inc.
 
Secure practices with dot net services.pptx
Secure practices with dot net services.pptxSecure practices with dot net services.pptx
Secure practices with dot net services.pptx
Knoldus Inc.
 
Distributed Cache with dot microservices
Distributed Cache with dot microservicesDistributed Cache with dot microservices
Distributed Cache with dot microservices
Knoldus Inc.
 
Introduction to gRPC Presentation (Java)
Introduction to gRPC Presentation (Java)Introduction to gRPC Presentation (Java)
Introduction to gRPC Presentation (Java)
Knoldus Inc.
 
Using InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in JmeterUsing InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in Jmeter
Knoldus Inc.
 
Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)
Knoldus Inc.
 
Stakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) PresentationStakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) Presentation
Knoldus Inc.
 
Introduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) PresentationIntroduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) Presentation
Knoldus Inc.
 
Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)
Knoldus Inc.
 
Exploring Terramate DevOps (Presentation)
Exploring Terramate DevOps (Presentation)Exploring Terramate DevOps (Presentation)
Exploring Terramate DevOps (Presentation)
Knoldus Inc.
 
Clean Code in Test Automation Differentiating Between the Good and the Bad
Clean Code in Test Automation  Differentiating Between the Good and the BadClean Code in Test Automation  Differentiating Between the Good and the Bad
Clean Code in Test Automation Differentiating Between the Good and the Bad
Knoldus Inc.
 
Integrating AI Capabilities in Test Automation
Integrating AI Capabilities in Test AutomationIntegrating AI Capabilities in Test Automation
Integrating AI Capabilities in Test Automation
Knoldus Inc.
 
State Management with NGXS in Angular.pptx
State Management with NGXS in Angular.pptxState Management with NGXS in Angular.pptx
State Management with NGXS in Angular.pptx
Knoldus Inc.
 
Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
Knoldus Inc.
 
OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)
Knoldus Inc.
 
Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
Knoldus Inc.
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Knoldus Inc.
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
Knoldus Inc.
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
Knoldus Inc.
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
Knoldus Inc.
 

More from Knoldus Inc. (20)

Getting Started with Apache Spark (Scala)
Getting Started with Apache Spark (Scala)Getting Started with Apache Spark (Scala)
Getting Started with Apache Spark (Scala)
 
Secure practices with dot net services.pptx
Secure practices with dot net services.pptxSecure practices with dot net services.pptx
Secure practices with dot net services.pptx
 
Distributed Cache with dot microservices
Distributed Cache with dot microservicesDistributed Cache with dot microservices
Distributed Cache with dot microservices
 
Introduction to gRPC Presentation (Java)
Introduction to gRPC Presentation (Java)Introduction to gRPC Presentation (Java)
Introduction to gRPC Presentation (Java)
 
Using InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in JmeterUsing InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in Jmeter
 
Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)
 
Stakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) PresentationStakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) Presentation
 
Introduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) PresentationIntroduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) Presentation
 
Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)
 
Exploring Terramate DevOps (Presentation)
Exploring Terramate DevOps (Presentation)Exploring Terramate DevOps (Presentation)
Exploring Terramate DevOps (Presentation)
 
Clean Code in Test Automation Differentiating Between the Good and the Bad
Clean Code in Test Automation  Differentiating Between the Good and the BadClean Code in Test Automation  Differentiating Between the Good and the Bad
Clean Code in Test Automation Differentiating Between the Good and the Bad
 
Integrating AI Capabilities in Test Automation
Integrating AI Capabilities in Test AutomationIntegrating AI Capabilities in Test Automation
Integrating AI Capabilities in Test Automation
 
State Management with NGXS in Angular.pptx
State Management with NGXS in Angular.pptxState Management with NGXS in Angular.pptx
State Management with NGXS in Angular.pptx
 
Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
 
OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)
 
Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 

Recently uploaded

In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 

Recently uploaded (20)

In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 

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)