• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Functional Programming with LISP
 

Functional Programming with LISP

on

  • 2,880 views

 

Statistics

Views

Total Views
2,880
Views on SlideShare
2,173
Embed Views
707

Actions

Likes
2
Downloads
0
Comments
0

8 Embeds 707

http://profession.sarika-pugs.com 384
http://sysplay.in 287
http://localhost 23
http://www.sysplay.in 7
http://www.linkedin.com 2
https://www.linkedin.com 2
http://shrishti 1
http://coderwall.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Functional Programming with LISP Functional Programming with LISP Presentation Transcript

    • 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?Ws of LISPLanguage SpecificsFun 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 1956Name comes from its initial powerful List Processing featuresNatural computation mechanism: RecursionStandardization as Common LISP ANSI released standards in 1996Thought of as for Artificial Intelligence But could pretty much do anythingExamples range from OS, editors, compilers, games, GUIs, andyou think of it © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
    • Current Available FormsANSI Common Lisp: clisp Compiler, Interpreter, DebuggerGNU Common Lisp: gcl Compiler, InterpreterCMU Common Lisp: cmucl By Carnegie Mellon University Default available as .deb packages Use “alien –to-rpm" to convert them to rpmAllegro CL: Commercial Common Lisp implementation © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
    • Why LISP?“The programmable programming language"Whats good for the languages designer Is good for the languages usersWish for new features for easier programming? As you can just add the feature yourselfCode the way our brain thinks: Recursive Most natural way of programming50 lines of Code © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
    • Language SpecificsData StructuresBasic OperationsControl StructuresBasic I/O © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
    • Data StructuresS-Expression: Atom or ListAtom: String of characters (Values or Variables) Peace, 95432, -rtx, etcList: 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 OperationsLisp Program = Sequence of Functions Applied to their Arguments Returning Lisp ObjectsFunction 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)Lets try Commands: car, cdr, cons, quote Predicates: atom, nullNB Lisp is case-insensitiveMore: first, last, rest, append, consp, ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
    • Mathematical OperationsPredicates: zerop, plusp, evenp, integerp, floatpArithmetic: +, -, *, /, rem, 1+, 1-Comparisons: =, /=, <, >, <=, >=Rounding: floor, ceiling, truncate, roundMore Functions max, min, exp, expt, log, abs, signum, sqrt, isqrt © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
    • Control StructuresConstants & Variables: Atoms w/ & w/o quote ()Assignment: setq, psetq, set, setfConditionals: equal, cond, ifLogical: and, or, notFunctions (defun func-name (par1 … parn) (commands)) Unnamed: (lambda (par1 … parn) (commands)) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 12 All Rights Reserved.
    • Lets try some functionsExtract the second element from a listInsert an element at second position in a listChange nth element in a listFind 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 ProceduralRecursive Relation From Mathematics. Tricky Extreme Fairly Simple ConditionsTermination Needs Thought Fairly TrivialCondition Lets try some examples to understand © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
    • Tracing & AnalysisTracing 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 RecursionBottom most calls return = Topmost calls return Lets observe the trace on list reversalMay not be always possibleBut 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 OperationsSets: List of AToms (LATs)Operations: member, union, intersection, adjoinLets write some examples which support sets being elements of set © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 18 All Rights Reserved.
    • Basic Input / OutputBasic Input (read [input-stream] [eof-error] [eof-value]) → s-exprBasic 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 FilesLoading 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.
    • ReferencesCommon Lisp: http://www.lisp.orgCLISP: http://clisp.cons.orgPractical 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?Ws of LISPLanguage Specifics Demonstration Data Structures Basic Operations Control Structures Basic I/OFun 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.