SlideShare une entreprise Scribd logo
1  sur  23
Functional Programming
                       with

    LISt Processing


   © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
                  All Rights Reserved.
Introduction




© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
               All Rights Reserved.
What to Expect?
W's of LISP
Language Specifics
Fun with Recursion




          © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   3
                         All Rights Reserved.
What is LISP?
Functional Programming Language
  Conceived by John McCarthy in 1956
Name comes from its initial powerful List Processing features
Natural computation mechanism: Recursion
Standardization as Common LISP
  ANSI released standards in 1996
Thought of as for Artificial Intelligence
  But could pretty much do anything
Examples range from OS, editors, compilers, games, GUIs, and
you think of it
                 © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   4
                                All Rights Reserved.
Current Available Forms
ANSI Common Lisp: clisp
  Compiler, Interpreter, Debugger
GNU Common Lisp: gcl
  Compiler, Interpreter
CMU Common Lisp: cmucl
  By Carnegie Mellon University
  Default available as .deb packages
  Use “alien –to-rpm" to convert them to rpm
Allegro CL: Commercial Common Lisp implementation
               © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   5
                              All Rights Reserved.
Why LISP?
“The programmable programming language"
What's good for the language's designer
  Is good for the language's users
Wish for new features for easier programming?
  As you can just add the feature yourself
Code the way our brain thinks: Recursive
  Most natural way of programming
50 lines of Code
             © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   6
                            All Rights Reserved.
Language Specifics
Data Structures
Basic Operations
Control Structures
Basic I/O




             © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   7
                            All Rights Reserved.
Data Structures
S-Expression: Atom or List
Atom: String of characters ('Values or Variables)
  Peace, 95432, -rtx, etc
List: Collection of S-Expressions enclosed by ()
  (The 100 times done)
  (Guava (43 (2.718 5) 56) Apple)
What is a Null List: ()?
Common Pitfall: Lists need to start with '
             © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   8
                            All Rights Reserved.
Basic Operations
Lisp Program = Sequence of Functions
  Applied to their Arguments
  Returning Lisp Objects
Function Types
  Predicate
    Tests conditions with its arguments
    Returns Nil (FALSE) or anything else (TRUE)
  Command
    Performs operation with its arguments
    Returns an S-Expression
                © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   9
                               All Rights Reserved.
Basic Operations ...
Format: (function arg1 arg2 … argn)
Let's try
  Commands: car, cdr, cons, quote
  Predicates: atom, null
NB Lisp is case-insensitive
More: first, last, rest, append, consp, ...


             © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   10
                            All Rights Reserved.
Mathematical Operations
Predicates: zerop, plusp, evenp, integerp, floatp
Arithmetic: +, -, *, /, rem, 1+, 1-
Comparisons: =, /=, <, >, <=, >=
Rounding: floor, ceiling, truncate, round
More Functions
  max, min, exp, expt, log, abs, signum, sqrt, isqrt


             © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   11
                            All Rights Reserved.
Control Structures
Constants & Variables: Atoms w/ & w/o quote (')
Assignment: setq, psetq, set, setf
Conditionals: equal, cond, if
Logical: and, or, not
Functions
  (defun func-name (par1 … parn) (commands))
  Unnamed: (lambda (par1 … parn) (commands))

            © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   12
                           All Rights Reserved.
Let's try some functions
Extract the second element from a list
Insert an element at second position in a list
Change nth element in a list
Find length of a list (iteratively)
Find variance of a list of elements




             © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   13
                            All Rights Reserved.
Iteration is Human
     Recursion is God




© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   14
               All Rights Reserved.
Recursion
 For any recursion, we need 2 things
     Recursive Relation
     Termination Condition
                         Functional                Procedural

Recursive Relation   From Mathematics.       Tricky Extreme
                     Fairly Simple           Conditions

Termination          Needs Thought           Fairly Trivial
Condition



 Let's try some examples to understand
                     © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   15
                                    All Rights Reserved.
Tracing & Analysis
Tracing Recursive Function Calls
  Enable tracing: (trace recursive-func)
  Invoke the function to be traced: (recursive-func …)
Performance Analysis
  (time (func …))
  Samples with our recursive functions



            © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   16
                           All Rights Reserved.
Tail Recursion
Bottom most call's return = Topmost call's return
  Let's observe the trace on list reversal
May not be always possible
But if possible, it is a smart compiler advantage
  Cuts-off processing as soon as lowest level returns




             © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   17
                            All Rights Reserved.
Example: Set Operations
Sets: List of AToms (LATs)
Operations: member, union, intersection, adjoin
Let's write some examples
  which support sets being elements of set




            © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   18
                           All Rights Reserved.
Basic Input / Output
Basic Input
  (read [input-stream] [eof-error] [eof-value]) → s-expr
Basic Output
  (print s-expr [output-stream]) → s-expr
  (format destination control-string [args])




              © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   19
                             All Rights Reserved.
Loading Files
Loading Lisp file for interpretation
  (load "file.lisp")
Compiling a Lisp file
  (compile "file.lisp") or (compile "file")
Loading a compiled Lisp file
  (load (compile "file.lisp"))



              © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   20
                             All Rights Reserved.
References
Common Lisp: http://www.lisp.org
CLISP: http://clisp.cons.org
Practical Common Lisp by Peter Seibel
  Also @ http://www.gigamonkeys.com/book/
LISP Tutorial: http://www.mars.cs.unp.ac.za/lisp/




           © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   21
                          All Rights Reserved.
What all have we learnt?
W's of LISP
Language Specifics Demonstration
  Data Structures
  Basic Operations
  Control Structures
  Basic I/O
Fun with Recursion
  Power, Tail Recursion, Tracing & Analysis
              © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   22
                             All Rights Reserved.
Any Queries?




© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   23
               All Rights Reserved.

Contenu connexe

Tendances (20)

POSIX Threads
POSIX ThreadsPOSIX Threads
POSIX Threads
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
Bootloaders
BootloadersBootloaders
Bootloaders
 
Threads
ThreadsThreads
Threads
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
Toolchain
ToolchainToolchain
Toolchain
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Linux Internals Part - 2
Linux Internals Part - 2Linux Internals Part - 2
Linux Internals Part - 2
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
 
Linux Internals Part - 3
Linux Internals Part - 3Linux Internals Part - 3
Linux Internals Part - 3
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Linux File System
Linux File SystemLinux File System
Linux File System
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Timers
TimersTimers
Timers
 
Unix system calls
Unix system callsUnix system calls
Unix system calls
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 

En vedette (7)

Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
References
ReferencesReferences
References
 
Interrupts
InterruptsInterrupts
Interrupts
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 

Similaire à Functional Programming with LISP

Vasiliy Litvinov - Python Profiling
Vasiliy Litvinov - Python ProfilingVasiliy Litvinov - Python Profiling
Vasiliy Litvinov - Python ProfilingSergey Arkhipov
 
Massively Parallel Processing with Procedural Python by Ronert Obst PyData Be...
Massively Parallel Processing with Procedural Python by Ronert Obst PyData Be...Massively Parallel Processing with Procedural Python by Ronert Obst PyData Be...
Massively Parallel Processing with Procedural Python by Ronert Obst PyData Be...PyData
 
Lambdas And Streams Hands On Lab
Lambdas And Streams Hands On LabLambdas And Streams Hands On Lab
Lambdas And Streams Hands On LabSimon Ritter
 
Government Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptxGovernment Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptxShivamDenge
 
Massively Parallel Processing with Procedural Python (PyData London 2014)
Massively Parallel Processing with Procedural Python (PyData London 2014)Massively Parallel Processing with Procedural Python (PyData London 2014)
Massively Parallel Processing with Procedural Python (PyData London 2014)Ian Huston
 
Lambdas Hands On Lab
Lambdas Hands On LabLambdas Hands On Lab
Lambdas Hands On LabSimon Ritter
 
RSJ2011 OSS Robotics and Tools OpenHRI Intro
RSJ2011 OSS Robotics and Tools OpenHRI IntroRSJ2011 OSS Robotics and Tools OpenHRI Intro
RSJ2011 OSS Robotics and Tools OpenHRI IntroYosuke Matsusaka
 
Calcite meetup-2016-04-20
Calcite meetup-2016-04-20Calcite meetup-2016-04-20
Calcite meetup-2016-04-20Josh Elser
 
Python functional programming
Python functional programmingPython functional programming
Python functional programmingGeison Goes
 
Accelerating the Development of Efficient CP Optimizer Models
Accelerating the Development of Efficient CP Optimizer ModelsAccelerating the Development of Efficient CP Optimizer Models
Accelerating the Development of Efficient CP Optimizer ModelsPhilippe Laborie
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and FuturePushkar Kulkarni
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present FutureIndicThreads
 
Massively Parallel Process with Prodedural Python by Ian Huston
Massively Parallel Process with Prodedural Python by Ian HustonMassively Parallel Process with Prodedural Python by Ian Huston
Massively Parallel Process with Prodedural Python by Ian HustonPyData
 
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Srivatsan Ramanujam
 
Arista: DevOps for Network Engineers
Arista: DevOps for Network EngineersArista: DevOps for Network Engineers
Arista: DevOps for Network EngineersPhilip DiLeo
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fpAlexander Granin
 

Similaire à Functional Programming with LISP (20)

Vasiliy Litvinov - Python Profiling
Vasiliy Litvinov - Python ProfilingVasiliy Litvinov - Python Profiling
Vasiliy Litvinov - Python Profiling
 
Massively Parallel Processing with Procedural Python by Ronert Obst PyData Be...
Massively Parallel Processing with Procedural Python by Ronert Obst PyData Be...Massively Parallel Processing with Procedural Python by Ronert Obst PyData Be...
Massively Parallel Processing with Procedural Python by Ronert Obst PyData Be...
 
Lambdas And Streams Hands On Lab
Lambdas And Streams Hands On LabLambdas And Streams Hands On Lab
Lambdas And Streams Hands On Lab
 
Government Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptxGovernment Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptx
 
Shivam PPT.pptx
Shivam PPT.pptxShivam PPT.pptx
Shivam PPT.pptx
 
Massively Parallel Processing with Procedural Python (PyData London 2014)
Massively Parallel Processing with Procedural Python (PyData London 2014)Massively Parallel Processing with Procedural Python (PyData London 2014)
Massively Parallel Processing with Procedural Python (PyData London 2014)
 
JDK8 Streams
JDK8 StreamsJDK8 Streams
JDK8 Streams
 
Lambdas Hands On Lab
Lambdas Hands On LabLambdas Hands On Lab
Lambdas Hands On Lab
 
RSJ2011 OSS Robotics and Tools OpenHRI Intro
RSJ2011 OSS Robotics and Tools OpenHRI IntroRSJ2011 OSS Robotics and Tools OpenHRI Intro
RSJ2011 OSS Robotics and Tools OpenHRI Intro
 
Calcite meetup-2016-04-20
Calcite meetup-2016-04-20Calcite meetup-2016-04-20
Calcite meetup-2016-04-20
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
 
Accelerating the Development of Efficient CP Optimizer Models
Accelerating the Development of Efficient CP Optimizer ModelsAccelerating the Development of Efficient CP Optimizer Models
Accelerating the Development of Efficient CP Optimizer Models
 
Functional Programming - Past, Present and Future
Functional Programming - Past, Present and FutureFunctional Programming - Past, Present and Future
Functional Programming - Past, Present and Future
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Massively Parallel Process with Prodedural Python by Ian Huston
Massively Parallel Process with Prodedural Python by Ian HustonMassively Parallel Process with Prodedural Python by Ian Huston
Massively Parallel Process with Prodedural Python by Ian Huston
 
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
 
Arista: DevOps for Network Engineers
Arista: DevOps for Network EngineersArista: DevOps for Network Engineers
Arista: DevOps for Network Engineers
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fp
 
Flink internals web
Flink internals web Flink internals web
Flink internals web
 
"make" system
"make" system"make" system
"make" system
 

Plus de Anil Kumar Pugalia (9)

File System Modules
File System ModulesFile System Modules
File System Modules
 
Processes
ProcessesProcesses
Processes
 
System Calls
System CallsSystem Calls
System Calls
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
 
Power of vi
Power of viPower of vi
Power of vi
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 

Dernier

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 

Dernier (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 

Functional Programming with LISP

  • 1. Functional Programming with LISt Processing © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
  • 2. Introduction © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
  • 3. What to Expect? W's of LISP Language Specifics Fun with Recursion © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 3 All Rights Reserved.
  • 4. What is LISP? Functional Programming Language Conceived by John McCarthy in 1956 Name comes from its initial powerful List Processing features Natural computation mechanism: Recursion Standardization as Common LISP ANSI released standards in 1996 Thought of as for Artificial Intelligence But could pretty much do anything Examples range from OS, editors, compilers, games, GUIs, and you think of it © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
  • 5. Current Available Forms ANSI Common Lisp: clisp Compiler, Interpreter, Debugger GNU Common Lisp: gcl Compiler, Interpreter CMU Common Lisp: cmucl By Carnegie Mellon University Default available as .deb packages Use “alien –to-rpm" to convert them to rpm Allegro CL: Commercial Common Lisp implementation © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
  • 6. Why LISP? “The programmable programming language" What's good for the language's designer Is good for the language's users Wish for new features for easier programming? As you can just add the feature yourself Code the way our brain thinks: Recursive Most natural way of programming 50 lines of Code © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
  • 7. Language Specifics Data Structures Basic Operations Control Structures Basic I/O © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
  • 8. Data Structures S-Expression: Atom or List Atom: String of characters ('Values or Variables) Peace, 95432, -rtx, etc List: Collection of S-Expressions enclosed by () (The 100 times done) (Guava (43 (2.718 5) 56) Apple) What is a Null List: ()? Common Pitfall: Lists need to start with ' © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 8 All Rights Reserved.
  • 9. Basic Operations Lisp Program = Sequence of Functions Applied to their Arguments Returning Lisp Objects Function Types Predicate Tests conditions with its arguments Returns Nil (FALSE) or anything else (TRUE) Command Performs operation with its arguments Returns an S-Expression © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
  • 10. Basic Operations ... Format: (function arg1 arg2 … argn) Let's try Commands: car, cdr, cons, quote Predicates: atom, null NB Lisp is case-insensitive More: first, last, rest, append, consp, ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
  • 11. Mathematical Operations Predicates: zerop, plusp, evenp, integerp, floatp Arithmetic: +, -, *, /, rem, 1+, 1- Comparisons: =, /=, <, >, <=, >= Rounding: floor, ceiling, truncate, round More Functions max, min, exp, expt, log, abs, signum, sqrt, isqrt © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
  • 12. Control Structures Constants & Variables: Atoms w/ & w/o quote (') Assignment: setq, psetq, set, setf Conditionals: equal, cond, if Logical: and, or, not Functions (defun func-name (par1 … parn) (commands)) Unnamed: (lambda (par1 … parn) (commands)) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 12 All Rights Reserved.
  • 13. Let's try some functions Extract the second element from a list Insert an element at second position in a list Change nth element in a list Find length of a list (iteratively) Find variance of a list of elements © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 13 All Rights Reserved.
  • 14. Iteration is Human Recursion is God © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 14 All Rights Reserved.
  • 15. Recursion For any recursion, we need 2 things Recursive Relation Termination Condition Functional Procedural Recursive Relation From Mathematics. Tricky Extreme Fairly Simple Conditions Termination Needs Thought Fairly Trivial Condition Let's try some examples to understand © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
  • 16. Tracing & Analysis Tracing Recursive Function Calls Enable tracing: (trace recursive-func) Invoke the function to be traced: (recursive-func …) Performance Analysis (time (func …)) Samples with our recursive functions © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 16 All Rights Reserved.
  • 17. Tail Recursion Bottom most call's return = Topmost call's return Let's observe the trace on list reversal May not be always possible But if possible, it is a smart compiler advantage Cuts-off processing as soon as lowest level returns © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 17 All Rights Reserved.
  • 18. Example: Set Operations Sets: List of AToms (LATs) Operations: member, union, intersection, adjoin Let's write some examples which support sets being elements of set © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 18 All Rights Reserved.
  • 19. Basic Input / Output Basic Input (read [input-stream] [eof-error] [eof-value]) → s-expr Basic Output (print s-expr [output-stream]) → s-expr (format destination control-string [args]) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 19 All Rights Reserved.
  • 20. Loading Files Loading Lisp file for interpretation (load "file.lisp") Compiling a Lisp file (compile "file.lisp") or (compile "file") Loading a compiled Lisp file (load (compile "file.lisp")) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 20 All Rights Reserved.
  • 21. References Common Lisp: http://www.lisp.org CLISP: http://clisp.cons.org Practical Common Lisp by Peter Seibel Also @ http://www.gigamonkeys.com/book/ LISP Tutorial: http://www.mars.cs.unp.ac.za/lisp/ © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 21 All Rights Reserved.
  • 22. What all have we learnt? W's of LISP Language Specifics Demonstration Data Structures Basic Operations Control Structures Basic I/O Fun with Recursion Power, Tail Recursion, Tracing & Analysis © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 22 All Rights Reserved.
  • 23. Any Queries? © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 23 All Rights Reserved.