SlideShare a Scribd company logo
Lisp
                            Tijs van der Storm




Thursday, September 6, 12
About me...
                    • Work at Centrum Wiskunde & Informatica
                    • Teach at Universiteit van Amsterdam in the
                            Master Software Engineering
                    • According to @jvandenbos “typical esoteric
                            programming language dude” :)
                    • Contact: storm@cwi.nl, @tvdstorm

Thursday, September 6, 12
Interests and projects

                    • DSLs, MDD, programming, languages
                    • Co-designer of the Rascal
                            metaprogramming language
                    • Co-designer of the Ensō model-based
                            programming environment



Thursday, September 6, 12
Atze van der Ploeg




Thursday, September 6, 12
Today

                    • About Lisp
                    • Programming Clojure
                    • ... meta-programming



Thursday, September 6, 12
http://lambda.bugyo.tk/cdr/mwl/

Thursday, September 6, 12
What is Lisp?
                                                                    http://lisperati.com/
                    •       A programming language?
                    •       For LIst Processing?
                    •       The most intelligent way to misuse a computer?
                    •       Lots of Irritating Superfluous Parentheses?
                    •       Secret alien technology?
                    •       Oatmeal with fingernail clippings mixed in?
                    •       A programmer amplifier?


Thursday, September 6, 12
What is Lisp?

                    • A PL for building organisms (Perlis)
                    • Building material (Kay)
                    • Opposite of a Blub language (Graham)
                    • Maxwell’s equations of software (Kay)
                    • The greatest language ever invented (Kay)

Thursday, September 6, 12
John McCarthy




                                            (September 4, 1927 –
                                            October 24, 2011)

Thursday, September 6, 12
(




              Recursive Functions of Symbolic Expressions and
                   Their Computation by Machine, Part I
                              JOHX MCCAaTItY, Massachusetts Institute of Technology, Cambridge, Mass.


      1.   Introduction                                                2. F u n c t i o n s a n d F u n c t i o n Definitions
         A programming system called LISP (for lASt Processor)            We shMl need a number of mathematical ideas ar:d
      has been developed for the I B M 704 computer by the             notations concerning functions in general. Most of the
      Artificial Intelligence group at M.I.T. The system was           ideas are well known, but the notion of conditional e,~pre~'-
      designed to facilitate experiments with a proposed system        sion is believed to be new, and ihe use of conditional
      called the Advice Taker, whereby a machine could be              expressions permits functions to be defined recursively in a
      instructed to handle declarative as well as imperative           new and convenient way.
      sentences and could exhibit "common sense" in carrying              a. Partial Functions. A partial function is a funct on
      out its instructions. The original proposal It] for the Advice   that is defined only on part of its domain. Partial funetio:~s
      Taker was made in November 1958. The main require-               necessarily arise when functions are defined by eomputa~
      ment was a programming system for manipulating ex-               tions because for some values of the arguments t:he Pomp:>
      pressions representing formalized declarative and irnpera-       ration defining the value of the function may not ter-
      live sentences so that the Advice Taker system could make        minate. However, some of our elementary functions wilt be
      deductions.                                                      defined as partial functions.
         In the course of its development the Lisp system went
                                                                          b. Propositional Expres.s'ions and Predicates. A t)ropo~i-
      through several stages of simplification and eventually
                                                                       tionM expression is an expression whose possible values
      came to be based on a scheme for representing the partial
                                                                       are T (for truth) and F (for falsity). We shall assume
      recursive functions of a certain class of symbolic expres-
                                                                       that the reader is fanfiliar with the propositionM eom~ee-
      sions. This representation is independent of the IBM 704
                                                                       lives A ("and"), V ( " o r " ) , and ~ ( " n o t " ) , Typieai
      computer, or of any other electronic computer, and it now
                                                                       propositional expressions are:
      seems expedient to expound the system by starting with
      the class of expressions called S-expressions and the func-                              x<y
      tions called S-functions.
                                                                                              (x < y) A (b = e)
         In this article, we first describe a formalism for defining
      functions reeursively. We believe this formalism has ad-                                 x is prime
      vantages both as a programming language and as vehicle           A predicate is a function whose range consists of ih{:
      for developing a theory of computation. Next, we describe        truth values T and F.
      S-expressions and S-functions, give some examples, and
                                                                         e. Conditional Expressions. The dependence of truth
      then describe the universM S-function apply which plays
                                                                       values on the vahtes of quantities of other kinds is ex-
      the theoretical role of a universal Turing machine and
                                                                       pressed in mathematics by predicates, and the depende~ee
      the practical role of an interpreter. Then we describe the
                                                                       of truth values on other truth values by logical comxee-
      representation of S-expressions in the memmT of the
                                                                       ~ives. However, the notations for expressing symbol (alE"
      IBM 704 by list structures similar to those used by Newell,      the dependence of quantities of other kinds on trutt~
      Shaw and Simon [2], and the representation of S-functions        vMues is inadequate, so that English words and phrases
      by program. Then we mention the main features of the             are generMly used for expressing these depende~tces i:~
      Lisp programming system for the IBM 704. Next comes              texts that, describe other dependences symbolically. I!'<~r
      another way of describing computations with symbolic             example, the function Ix I is ustmlly defined in words.
      expressions, and finally we give a recursive function in-           Conditional expressions are a deviee for expressing the
      terpretation of flow charts.                                     dependence of quantities on propositional quantities. :
         We hope to describe some of the sylnbolie computations        conditional expression has the form
           Communications of the ACM, vol 3, issue 4, April 1960
      for which LISP has been used in another paper, and also to
      give elsewhere some applications of our reeursive function
                                                                                           (p: -+ el,    -.-   , p ~ --+ e , , )   http://dx.doi.org/10.1145/367177.367199
      formalism to mathematical logic and to the problem of            where the p's are propositionM expressions and the e's are
      mechanical theorem proving.                                      expressions of any kind. It may be read, "If p~ thexx <,
Thursday, September 6, 12
Last 17th of
                                                            August: 50 years
                                                                ago (!)




  http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
Thursday, September 6, 12
The famous
                             page 13




                             http://xkcd.com/917/

Thursday, September 6, 12
Guy L. Steele, Richard P. Gabriel, “The evolution of Lisp”, in: History of programming languages II, ACM 1996, p. 311


Thursday, September 6, 12
Revised5 Report on the Algorithmic Language
                                    Scheme
                                      RICHARD   KELSEY, WILLIAM CLINGER, AND JONATHAN REES (Editors)
                         H. ABELSON             R. K. DYBVIG             C. T. HAYNES           G. J. ROZAS
                         N. I. ADAMS IV         D. P. FRIEDMAN           E. KOHLBECKER          G. L. STEELE JR.
                         D. H. BARTLEY          R. HALSTEAD              D. OXLEY               G. J. SUSSMAN
                         G. BROOKS              C. HANSON                K. M. PITMAN           M. WAND


                                                     Dedicated to the Memory of Robert Hieb

                                20 February 1998                                                     CONTENTS
                                                                           Introduction . . . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .    2


                                                                                                                                                                        50 pages:
                                  SUMMARY                                  1 Overview of Scheme . . . . . . . . . . . . . . . .       .   .   .   .   .   .   .    3
                                                                               1.1 Semantics . . . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .    3
             The report gives a defining description of the program-            1.2 Syntax . . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .    3
             ming language Scheme. Scheme is a statically scoped and           1.3 Notation and terminology . . . . . . . . .         .   .   .   .   .   .   .    3



                                                                                                                                                                       pure, small,
             properly tail-recursive dialect of the Lisp programming       2 Lexical conventions . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .    5
             language invented by Guy Lewis Steele Jr. and Gerald              2.1 Identifiers . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .    5
             Jay Sussman. It was designed to have an exceptionally             2.2 Whitespace and comments . . . . . . . . .          .   .   .   .   .   .   .    5
             clear and simple semantics and few di↵erent ways to form          2.3 Other notations . . . . . . . . . . . . . . .      .   .   .   .   .   .   .    5



                                                                                                                                                                       “academic”
                                                                           3 Basic concepts . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .    6
             expressions. A wide variety of programming paradigms, in-
                                                                               3.1 Variables, syntactic keywords, and regions         .   .   .   .   .   .   .    6
             cluding imperative, functional, and message passing styles,
                                                                               3.2 Disjointness of types . . . . . . . . . . . .      .   .   .   .   .   .   .    6
             find convenient expression in Scheme.                              3.3 External representations . . . . . . . . . .       .   .   .   .   .   .   .    6
             The introduction o↵ers a brief history of the language and        3.4 Storage model . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .    7
             of the report.                                                    3.5 Proper tail recursion . . . . . . . . . . . .      .   .   .   .   .   .   .    7
                                                                           4 Expressions . . . . . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .    8
             The first three chapters present the fundamental ideas of          4.1 Primitive expression types . . . . . . . . .       .   .   .   .   .   .   .    8
             the language and describe the notational conventions used         4.2 Derived expression types . . . . . . . . . .       .   .   .   .   .   .   .   10
             for describing the language and for writing programs in the       4.3 Macros . . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .   13
             language.                                                     5 Program structure . . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .   16
                                                                               5.1 Programs . . . . . . . . . . . . . . . . . .       .   .   .   .   .   .   .   16
             Chapters 4 and 5 describe the syntax and semantics of             5.2 Definitions . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .   16
             expressions, programs, and definitions.                            5.3 Syntax definitions . . . . . . . . . . . . .        .   .   .   .   .   .   .   17
             Chapter 6 describes Scheme’s built-in procedures, which       6 Standard procedures . . . . . . . . . . . . . . .        .   .   .   .   .   .   .   17
             include all of the language’s data manipulation and in-           6.1 Equivalence predicates . . . . . . . . . . .       .   .   .   .   .   .   .   17
                                                                               6.2 Numbers . . . . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .   19
             put/output primitives.
                                                                               6.3 Other data types . . . . . . . . . . . . . .       .   .   .   .   .   .   .   25
             Chapter 7 provides a formal syntax for Scheme written in          6.4 Control features . . . . . . . . . . . . . . .     .   .   .   .   .   .   .   31
             extended BNF, along with a formal denotational semantics.         6.5 Eval . . . . . . . . . . . . . . . . . . . . .     .   .   .   .   .   .   .   35
             An example of the use of the language follows the formal          6.6 Input and output . . . . . . . . . . . . . .       .   .   .   .   .   .   .   35
             syntax and semantics.                                         7 Formal syntax and semantics . . . . . . . . . . .        .   .   .   .   .   .   .   38
                                                                               7.1 Formal syntax . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .   38
             The report concludes with a list of references and an al-         7.2 Formal semantics . . . . . . . . . . . . . .       .   .   .   .   .   .   .   40
             phabetic index.                                                   7.3 Derived expression types . . . . . . . . . .       .   .   .   .   .   .   .   43
                                                                           Notes . . . . . . . . . . . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   45
                                                                           Additional material . . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .   45
                                                                           Example . . . . . . . . . . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   45
                                                                           References . . . . . . . . . . . . . . . . . . . . . . .   .   .   .   .   .   .   .   46
                                                                           Alphabetic index of definitions of concepts,
                                                                                   keywords, and procedures . . . . . . . . .         . . . . . . .               48




Thursday, September 6, 12
1029 pages:
                            comprehensive, practical,
                               messy, “industrial”




Thursday, September 6, 12
What made Lisp different?




                            http://paulgraham.com/diff.html

Thursday, September 6, 12
How is Lisp still different?
                    • Homoiconic syntax
                     • aka: there is no syntax
                    • Macros
                     • aka: compile-time code transformers
                    • Code is data, data can be code
                    • Program into the language
Thursday, September 6, 12
http://xkcd.com/224/


Thursday, September 6, 12
Thursday, September 6, 12
Fun resources




Thursday, September 6, 12
http://xkcd.com/297/


Thursday, September 6, 12
Rich Hickey




Thursday, September 6, 12
• Lisp syntax, macros, code as data etc.
                    • Functional programming, immutable data
                    • Data structures: map, set, vector, list
                    • Concurrency: transactional memory
                    • Compiles to JVM, intergrates with Java
                    • [and much more]
Thursday, September 6, 12
(def basic-data-types
             '{:booleans [true, false]
               :numbers [1, 2, 3.0, 4/5]
               :strings ["this is a string"]
               :symbols [a, empty?, +, user/foo]
               :keywords [:a-key-word]})


                                     NB: commas, are
                                      whitespace (!)
Thursday, September 6, 12
(def collection-types
                      '{:vectors [1,2,3,4]
                        :maps     {:x 3, :y 4}
                        :sets     #{a set of symbols}
                        :lists    (a list of symbols)})




Thursday, September 6, 12
• Expressed using lists (Polish notation):
                            (operator arg1 arg2 ...)

                    • Head is applied to the arguments in tail:
                            (+ 1 2)




Thursday, September 6, 12
Special forms
             define          (def x 3)


     conditional            (if (> x 1) 'then 'else)

                            (do
     sequencing               (print "hello")
                              (print "world!"))

      local vars            (let [x 1] (+ x 1))

                            (quote (this returns a list with seven symbols))
       quotation            '(this returns a list with seven symbols)

          closures          (fn [x n] (+ x n))




Thursday, September 6, 12
Convenience macros
                   define a       (defn power [x n]
                   function        (if (= n 0)
                                     1
                                     (* x (power x (- n 1)))))




                    define a       (defmacro unless [cond then else]
                     macro          `(if (not ~cond) ~then ~else))




Thursday, September 6, 12
Macros!
                    • Functions that transform code trees
                    • aka: code that writes code
                template       (defmacro unless [cond then else]
                                 `(if (not ~cond) ~then ~else))



                            quasi quote `         unquote ~



Thursday, September 6, 12
Trying it in the REPL
           => (defmacro unless [cond then else]
                `(if (not ~cond) ~then ~else))
           #'user/unless

           => (unless (> 2 3) 'yes 'no)
           yes

           => (macroexpand '(unless (> 2 3) 'yes 'no))
           (if (clojure.core/not (> 2 3)) (quote yes) (quote no))

           => (macroexpand '(unless (> 2 3) (+ 1 2) (* 2 3)))
           (if (clojure.core/not (> 2 3)) (+ 1 2) (* 2 3))




Thursday, September 6, 12
Cascading conditionals
    (cond' [(> x y) 1]
           [(< x y) -1]
           [(= x y) 0]))
                                                         rest params
                            (defmacro cond' [case & cases]
                              (if (empty? cases)
                                `(when ~(first case)           splicing
                                   ~(second case))           unquote ~@
                                `(if ~(first case)
                                   ~(second case)
              macro                (cond' ~(first cases) ~@(rest cases)))))
            recursion


Thursday, September 6, 12
Testing it out
                       => ((fn [x y] (cond'
                                       [(> x y) 1]
                                       [(< x y) -1]
                                       [(= x y) 0])) 1 2)
                       -1

                       => (macroexpand-all '(cond'
                                              [(> x   y) 1]
                                              [(< x   y) -1]
                                              [(= x   y) 0]))
                       (if (> x y) 1 (if (< x y) -1   (if (= x y) (do 0))))




Thursday, September 6, 12
Why is this cool?
                    • Extend the language with new abstractions
                     • control-flow
                     • state machine
                     • GUI builders
                     • grammars, ... etc.
                    • Reuse Lisp syntax / compile with macros
Thursday, September 6, 12
s




                            http://www.cwi.nl/~storm/devclj.html

Thursday, September 6, 12

More Related Content

PPTX
Prolog & lisp
PPTX
A brief introduction to lisp language
PDF
Gentle Introduction To Lisp
PPT
PPT
INTRODUCTION TO LISP
ODP
Introduction to Programming in LISP
PPTX
Prolog & lisp
A brief introduction to lisp language
Gentle Introduction To Lisp
INTRODUCTION TO LISP
Introduction to Programming in LISP

What's hot (20)

PPTX
PPT
Advance LISP (Artificial Intelligence)
PPT
Lisp Programming Languge
PDF
Introduction To Lisp
PPTX
Basic lisp
PPT
(Ai lisp)
PPTX
LISP: Data types in lisp
PPTX
LISP: Input And Output
PDF
Lisp for Python Programmers
PPTX
LISP: Introduction to lisp
PDF
Real World Haskell: Lecture 7
PPT
Logic Programming and Prolog
PPT
BayFP: Concurrent and Multicore Haskell
PDF
Real World Haskell: Lecture 1
PDF
DEFUN 2008 - Real World Haskell
PPTX
Scheme Programming Language
PPTX
Introduction to Python Part-1
PPTX
Knowledge Extraction
PDF
Introduction to Functional Languages
PPT
Lisp and scheme i
Advance LISP (Artificial Intelligence)
Lisp Programming Languge
Introduction To Lisp
Basic lisp
(Ai lisp)
LISP: Data types in lisp
LISP: Input And Output
Lisp for Python Programmers
LISP: Introduction to lisp
Real World Haskell: Lecture 7
Logic Programming and Prolog
BayFP: Concurrent and Multicore Haskell
Real World Haskell: Lecture 1
DEFUN 2008 - Real World Haskell
Scheme Programming Language
Introduction to Python Part-1
Knowledge Extraction
Introduction to Functional Languages
Lisp and scheme i
Ad

Viewers also liked (20)

PPTX
LISP Programming Language (Artificial Intelligence)
PPT
Artificial intelligence Prolog Language
PPT
Prolog basics
PDF
Heroku
PDF
Lecture 3 basic syntax and semantics
PPT
02-Unidad 1 Generalidades de la Inteligencia Artificial
PDF
Redesigning Common Lisp
PPTX
Digital image processing
PPTX
PPT
Image processing1 introduction
PDF
Digital Image Processing: An Introduction
PPTX
Introduccion a los lenguajes de programacion para Inteligencia Artificial
PPS
Proyecto Areas Inteligencia Artificial Javier Garcia
PPT
Syntax and semantics
PPT
Digital Image Processing
PPT
Expert systems
PPTX
Digital image processing
PPT
Application of expert system
PPT
Introduction and architecture of expert system
PDF
Programming language design_concepts
LISP Programming Language (Artificial Intelligence)
Artificial intelligence Prolog Language
Prolog basics
Heroku
Lecture 3 basic syntax and semantics
02-Unidad 1 Generalidades de la Inteligencia Artificial
Redesigning Common Lisp
Digital image processing
Image processing1 introduction
Digital Image Processing: An Introduction
Introduccion a los lenguajes de programacion para Inteligencia Artificial
Proyecto Areas Inteligencia Artificial Javier Garcia
Syntax and semantics
Digital Image Processing
Expert systems
Digital image processing
Application of expert system
Introduction and architecture of expert system
Programming language design_concepts
Ad

Similar to Learn a language : LISP (20)

PPTX
Let's LISP like it's 1959
PPT
Artificial Intelligence Lecture Slide-05
PPTX
Functional Programming.pptx
PPTX
LISP: назад в будущее, Микола Мозговий
PDF
Clqr a4-consec
PPT
Chaps 1-3-ai-prolog
PPTX
Funtional Programming
PPTX
Class 27: Pythonic Objects
PDF
Unified Programming Theory
PPTX
Class 22: Stateful Evaluation Rules
PPTX
Not Everything is an Object - Rocksolid Tour 2013
PPTX
Univ of va intentional introduction 2013 01-31
PDF
An Abstraction-Based Genetic Programming System
PPT
kalaivaanar_NSK_V3.ppt
PDF
Induced Intentional Software Views
PPTX
System Verilog 2009 & 2012 enhancements
PPT
PDF
Theories of Programming Languages 1st Edition John C. Reynolds
PPTX
Class 26: Objectifying Objects
Let's LISP like it's 1959
Artificial Intelligence Lecture Slide-05
Functional Programming.pptx
LISP: назад в будущее, Микола Мозговий
Clqr a4-consec
Chaps 1-3-ai-prolog
Funtional Programming
Class 27: Pythonic Objects
Unified Programming Theory
Class 22: Stateful Evaluation Rules
Not Everything is an Object - Rocksolid Tour 2013
Univ of va intentional introduction 2013 01-31
An Abstraction-Based Genetic Programming System
kalaivaanar_NSK_V3.ppt
Induced Intentional Software Views
System Verilog 2009 & 2012 enhancements
Theories of Programming Languages 1st Edition John C. Reynolds
Class 26: Objectifying Objects

More from Devnology (20)

PDF
What do we really know about the differences between static and dynamic types?
PDF
Meetup at SIG: Meten is weten
PDF
Software Operation Knowledge
PPTX
Slides Felienne Hermans Symposium EWI
PDF
Devnology auteursrecht en open source 20130205
PDF
The top 10 security issues in web applications
PDF
Hacking Smartcards & RFID
PDF
Learn a language : LISP
PDF
Devnology Back to School: Empirical Evidence on Modeling in Software Development
PDF
Devnology Back to School IV - Agility en Architectuur
PDF
Devnology Back to School III : Software impact
PDF
Devnology back toschool software reengineering
PDF
Introduction to Software Evolution: The Software Volcano
PPT
Devnology Workshop Genpro 2 feb 2011
PPT
Devnology Coding Dojo 05-01-2011
PDF
Spoofax: ontwikkeling van domeinspecifieke talen in Eclipse
PDF
Experimenting with Augmented Reality
PPTX
Unit testing and MVVM in Silverlight
PDF
mobl: Een DSL voor mobiele applicatieontwikkeling
PPTX
Devnology Fitnesse workshop
What do we really know about the differences between static and dynamic types?
Meetup at SIG: Meten is weten
Software Operation Knowledge
Slides Felienne Hermans Symposium EWI
Devnology auteursrecht en open source 20130205
The top 10 security issues in web applications
Hacking Smartcards & RFID
Learn a language : LISP
Devnology Back to School: Empirical Evidence on Modeling in Software Development
Devnology Back to School IV - Agility en Architectuur
Devnology Back to School III : Software impact
Devnology back toschool software reengineering
Introduction to Software Evolution: The Software Volcano
Devnology Workshop Genpro 2 feb 2011
Devnology Coding Dojo 05-01-2011
Spoofax: ontwikkeling van domeinspecifieke talen in Eclipse
Experimenting with Augmented Reality
Unit testing and MVVM in Silverlight
mobl: Een DSL voor mobiele applicatieontwikkeling
Devnology Fitnesse workshop

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Review of recent advances in non-invasive hemoglobin estimation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
A comparative analysis of optical character recognition models for extracting...
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
MYSQL Presentation for SQL database connectivity
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Electronic commerce courselecture one. Pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Learn a language : LISP

  • 1. Lisp Tijs van der Storm Thursday, September 6, 12
  • 2. About me... • Work at Centrum Wiskunde & Informatica • Teach at Universiteit van Amsterdam in the Master Software Engineering • According to @jvandenbos “typical esoteric programming language dude” :) • Contact: storm@cwi.nl, @tvdstorm Thursday, September 6, 12
  • 3. Interests and projects • DSLs, MDD, programming, languages • Co-designer of the Rascal metaprogramming language • Co-designer of the Ensō model-based programming environment Thursday, September 6, 12
  • 4. Atze van der Ploeg Thursday, September 6, 12
  • 5. Today • About Lisp • Programming Clojure • ... meta-programming Thursday, September 6, 12
  • 7. What is Lisp? http://lisperati.com/ • A programming language? • For LIst Processing? • The most intelligent way to misuse a computer? • Lots of Irritating Superfluous Parentheses? • Secret alien technology? • Oatmeal with fingernail clippings mixed in? • A programmer amplifier? Thursday, September 6, 12
  • 8. What is Lisp? • A PL for building organisms (Perlis) • Building material (Kay) • Opposite of a Blub language (Graham) • Maxwell’s equations of software (Kay) • The greatest language ever invented (Kay) Thursday, September 6, 12
  • 9. John McCarthy (September 4, 1927 – October 24, 2011) Thursday, September 6, 12
  • 10. ( Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I JOHX MCCAaTItY, Massachusetts Institute of Technology, Cambridge, Mass. 1. Introduction 2. F u n c t i o n s a n d F u n c t i o n Definitions A programming system called LISP (for lASt Processor) We shMl need a number of mathematical ideas ar:d has been developed for the I B M 704 computer by the notations concerning functions in general. Most of the Artificial Intelligence group at M.I.T. The system was ideas are well known, but the notion of conditional e,~pre~'- designed to facilitate experiments with a proposed system sion is believed to be new, and ihe use of conditional called the Advice Taker, whereby a machine could be expressions permits functions to be defined recursively in a instructed to handle declarative as well as imperative new and convenient way. sentences and could exhibit "common sense" in carrying a. Partial Functions. A partial function is a funct on out its instructions. The original proposal It] for the Advice that is defined only on part of its domain. Partial funetio:~s Taker was made in November 1958. The main require- necessarily arise when functions are defined by eomputa~ ment was a programming system for manipulating ex- tions because for some values of the arguments t:he Pomp:> pressions representing formalized declarative and irnpera- ration defining the value of the function may not ter- live sentences so that the Advice Taker system could make minate. However, some of our elementary functions wilt be deductions. defined as partial functions. In the course of its development the Lisp system went b. Propositional Expres.s'ions and Predicates. A t)ropo~i- through several stages of simplification and eventually tionM expression is an expression whose possible values came to be based on a scheme for representing the partial are T (for truth) and F (for falsity). We shall assume recursive functions of a certain class of symbolic expres- that the reader is fanfiliar with the propositionM eom~ee- sions. This representation is independent of the IBM 704 lives A ("and"), V ( " o r " ) , and ~ ( " n o t " ) , Typieai computer, or of any other electronic computer, and it now propositional expressions are: seems expedient to expound the system by starting with the class of expressions called S-expressions and the func- x<y tions called S-functions. (x < y) A (b = e) In this article, we first describe a formalism for defining functions reeursively. We believe this formalism has ad- x is prime vantages both as a programming language and as vehicle A predicate is a function whose range consists of ih{: for developing a theory of computation. Next, we describe truth values T and F. S-expressions and S-functions, give some examples, and e. Conditional Expressions. The dependence of truth then describe the universM S-function apply which plays values on the vahtes of quantities of other kinds is ex- the theoretical role of a universal Turing machine and pressed in mathematics by predicates, and the depende~ee the practical role of an interpreter. Then we describe the of truth values on other truth values by logical comxee- representation of S-expressions in the memmT of the ~ives. However, the notations for expressing symbol (alE" IBM 704 by list structures similar to those used by Newell, the dependence of quantities of other kinds on trutt~ Shaw and Simon [2], and the representation of S-functions vMues is inadequate, so that English words and phrases by program. Then we mention the main features of the are generMly used for expressing these depende~tces i:~ Lisp programming system for the IBM 704. Next comes texts that, describe other dependences symbolically. I!'<~r another way of describing computations with symbolic example, the function Ix I is ustmlly defined in words. expressions, and finally we give a recursive function in- Conditional expressions are a deviee for expressing the terpretation of flow charts. dependence of quantities on propositional quantities. : We hope to describe some of the sylnbolie computations conditional expression has the form Communications of the ACM, vol 3, issue 4, April 1960 for which LISP has been used in another paper, and also to give elsewhere some applications of our reeursive function (p: -+ el, -.- , p ~ --+ e , , ) http://dx.doi.org/10.1145/367177.367199 formalism to mathematical logic and to the problem of where the p's are propositionM expressions and the e's are mechanical theorem proving. expressions of any kind. It may be read, "If p~ thexx <, Thursday, September 6, 12
  • 11. Last 17th of August: 50 years ago (!) http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf Thursday, September 6, 12
  • 12. The famous page 13 http://xkcd.com/917/ Thursday, September 6, 12
  • 13. Guy L. Steele, Richard P. Gabriel, “The evolution of Lisp”, in: History of programming languages II, ACM 1996, p. 311 Thursday, September 6, 12
  • 14. Revised5 Report on the Algorithmic Language Scheme RICHARD KELSEY, WILLIAM CLINGER, AND JONATHAN REES (Editors) H. ABELSON R. K. DYBVIG C. T. HAYNES G. J. ROZAS N. I. ADAMS IV D. P. FRIEDMAN E. KOHLBECKER G. L. STEELE JR. D. H. BARTLEY R. HALSTEAD D. OXLEY G. J. SUSSMAN G. BROOKS C. HANSON K. M. PITMAN M. WAND Dedicated to the Memory of Robert Hieb 20 February 1998 CONTENTS Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 50 pages: SUMMARY 1 Overview of Scheme . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 Semantics . . . . . . . . . . . . . . . . . . . . . . . . . 3 The report gives a defining description of the program- 1.2 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 ming language Scheme. Scheme is a statically scoped and 1.3 Notation and terminology . . . . . . . . . . . . . . . . 3 pure, small, properly tail-recursive dialect of the Lisp programming 2 Lexical conventions . . . . . . . . . . . . . . . . . . . . . . . 5 language invented by Guy Lewis Steele Jr. and Gerald 2.1 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . 5 Jay Sussman. It was designed to have an exceptionally 2.2 Whitespace and comments . . . . . . . . . . . . . . . . 5 clear and simple semantics and few di↵erent ways to form 2.3 Other notations . . . . . . . . . . . . . . . . . . . . . . 5 “academic” 3 Basic concepts . . . . . . . . . . . . . . . . . . . . . . . . . . 6 expressions. A wide variety of programming paradigms, in- 3.1 Variables, syntactic keywords, and regions . . . . . . . 6 cluding imperative, functional, and message passing styles, 3.2 Disjointness of types . . . . . . . . . . . . . . . . . . . 6 find convenient expression in Scheme. 3.3 External representations . . . . . . . . . . . . . . . . . 6 The introduction o↵ers a brief history of the language and 3.4 Storage model . . . . . . . . . . . . . . . . . . . . . . . 7 of the report. 3.5 Proper tail recursion . . . . . . . . . . . . . . . . . . . 7 4 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 The first three chapters present the fundamental ideas of 4.1 Primitive expression types . . . . . . . . . . . . . . . . 8 the language and describe the notational conventions used 4.2 Derived expression types . . . . . . . . . . . . . . . . . 10 for describing the language and for writing programs in the 4.3 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 language. 5 Program structure . . . . . . . . . . . . . . . . . . . . . . . . 16 5.1 Programs . . . . . . . . . . . . . . . . . . . . . . . . . 16 Chapters 4 and 5 describe the syntax and semantics of 5.2 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 16 expressions, programs, and definitions. 5.3 Syntax definitions . . . . . . . . . . . . . . . . . . . . 17 Chapter 6 describes Scheme’s built-in procedures, which 6 Standard procedures . . . . . . . . . . . . . . . . . . . . . . 17 include all of the language’s data manipulation and in- 6.1 Equivalence predicates . . . . . . . . . . . . . . . . . . 17 6.2 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 19 put/output primitives. 6.3 Other data types . . . . . . . . . . . . . . . . . . . . . 25 Chapter 7 provides a formal syntax for Scheme written in 6.4 Control features . . . . . . . . . . . . . . . . . . . . . . 31 extended BNF, along with a formal denotational semantics. 6.5 Eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 An example of the use of the language follows the formal 6.6 Input and output . . . . . . . . . . . . . . . . . . . . . 35 syntax and semantics. 7 Formal syntax and semantics . . . . . . . . . . . . . . . . . . 38 7.1 Formal syntax . . . . . . . . . . . . . . . . . . . . . . . 38 The report concludes with a list of references and an al- 7.2 Formal semantics . . . . . . . . . . . . . . . . . . . . . 40 phabetic index. 7.3 Derived expression types . . . . . . . . . . . . . . . . . 43 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Additional material . . . . . . . . . . . . . . . . . . . . . . . . 45 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Alphabetic index of definitions of concepts, keywords, and procedures . . . . . . . . . . . . . . . . 48 Thursday, September 6, 12
  • 15. 1029 pages: comprehensive, practical, messy, “industrial” Thursday, September 6, 12
  • 16. What made Lisp different? http://paulgraham.com/diff.html Thursday, September 6, 12
  • 17. How is Lisp still different? • Homoiconic syntax • aka: there is no syntax • Macros • aka: compile-time code transformers • Code is data, data can be code • Program into the language Thursday, September 6, 12
  • 23. • Lisp syntax, macros, code as data etc. • Functional programming, immutable data • Data structures: map, set, vector, list • Concurrency: transactional memory • Compiles to JVM, intergrates with Java • [and much more] Thursday, September 6, 12
  • 24. (def basic-data-types '{:booleans [true, false] :numbers [1, 2, 3.0, 4/5] :strings ["this is a string"] :symbols [a, empty?, +, user/foo] :keywords [:a-key-word]}) NB: commas, are whitespace (!) Thursday, September 6, 12
  • 25. (def collection-types '{:vectors [1,2,3,4] :maps {:x 3, :y 4} :sets #{a set of symbols} :lists (a list of symbols)}) Thursday, September 6, 12
  • 26. • Expressed using lists (Polish notation): (operator arg1 arg2 ...) • Head is applied to the arguments in tail: (+ 1 2) Thursday, September 6, 12
  • 27. Special forms define (def x 3) conditional (if (> x 1) 'then 'else) (do sequencing (print "hello") (print "world!")) local vars (let [x 1] (+ x 1)) (quote (this returns a list with seven symbols)) quotation '(this returns a list with seven symbols) closures (fn [x n] (+ x n)) Thursday, September 6, 12
  • 28. Convenience macros define a (defn power [x n] function (if (= n 0) 1 (* x (power x (- n 1))))) define a (defmacro unless [cond then else] macro `(if (not ~cond) ~then ~else)) Thursday, September 6, 12
  • 29. Macros! • Functions that transform code trees • aka: code that writes code template (defmacro unless [cond then else] `(if (not ~cond) ~then ~else)) quasi quote ` unquote ~ Thursday, September 6, 12
  • 30. Trying it in the REPL => (defmacro unless [cond then else] `(if (not ~cond) ~then ~else)) #'user/unless => (unless (> 2 3) 'yes 'no) yes => (macroexpand '(unless (> 2 3) 'yes 'no)) (if (clojure.core/not (> 2 3)) (quote yes) (quote no)) => (macroexpand '(unless (> 2 3) (+ 1 2) (* 2 3))) (if (clojure.core/not (> 2 3)) (+ 1 2) (* 2 3)) Thursday, September 6, 12
  • 31. Cascading conditionals (cond' [(> x y) 1] [(< x y) -1] [(= x y) 0])) rest params (defmacro cond' [case & cases] (if (empty? cases) `(when ~(first case) splicing ~(second case)) unquote ~@ `(if ~(first case) ~(second case) macro (cond' ~(first cases) ~@(rest cases))))) recursion Thursday, September 6, 12
  • 32. Testing it out => ((fn [x y] (cond' [(> x y) 1] [(< x y) -1] [(= x y) 0])) 1 2) -1 => (macroexpand-all '(cond' [(> x y) 1] [(< x y) -1] [(= x y) 0])) (if (> x y) 1 (if (< x y) -1 (if (= x y) (do 0)))) Thursday, September 6, 12
  • 33. Why is this cool? • Extend the language with new abstractions • control-flow • state machine • GUI builders • grammars, ... etc. • Reuse Lisp syntax / compile with macros Thursday, September 6, 12
  • 34. s http://www.cwi.nl/~storm/devclj.html Thursday, September 6, 12