SlideShare una empresa de Scribd logo
1 de 55
http://www.flickr.com/photos/dust/3603580129/ (CC Attribution)




                                        Lisp
           (Gauche                                                    )
2.1
2
2000       EY-Office




       3
4
Lisp




       5
New York           “The
                                                           lisps”            Sammy
                                                           Tunis

                                                           flickr    ”lisp”




http://www.flickr.com/photos/dust/3603580129/ (CC Attribution)

                                                       6
Lisp

S

Lisp

       (Lisp       )

               7
Lisp


       http://www.flickr.com/photos/dust/3603580129/ (CC Attribution)


         8
Lisp             LL
1960           1970                        1980                       1990                            2000


FORTAN                 C                              C++                                    Java            C#


 ALGOL           Pascal


             Simula

  COBOL




   Lisp1.5                                        Common
                                                    Lisp


                                      Scheme
                                                                      Perl            Ruby


                          Smalltalk                                          Python



                                                                                         Javascript
                                                            Haskell
                      Prolog


                                                  9
Lisp
                    Perl,Ruby,Python,
                      Javascript ...




                     Java,Perl,Ruby,
                        Python,
                      Javascript ...


 (Lisp)                Haskell,Scale
                          (Ruby,
                       Javascript...)




               !?

                     !?
          10
11
GC (Garbage collection)




           12
13
(Symbolic Expression)




       14
15
S


    http://www.flickr.com/photos/dust/3603580129/ (CC Attribution)


     16
S




    17
S




    18
S




    19
S




    20
S




    21
S




    22
23
24
Lisp



       http://www.flickr.com/photos/dust/3603580129/ (CC Attribution)


         25
% rlwrap gosh
gosh> (+ 1 2)
3
gosh> (* 2 (+ 3 4))
14
gosh>




                26
gosh>   (define a 3)
a
gosh>   a
3
gosh>   (define b (+ 2 5))
b
gosh>   b
7
gosh>   (+ a b)
10

                  27
gosh> (set! a (+ a 1))
4
gosh> a
4
gosh> c
*** ERROR: unbound variable: c
gosh>


                28
gosh> (let ((a 2)
            (b 3))
        (set! a (+ a 1))
        (+ a b))
6
gosh>




                29
gosh> (define (add3 n) (+ n 3))
add3
gosh> (add3 5)
8
gosh> (add3 (add3 4))
10



                30
quote

gosh> c
*** ERROR: unbound variable: c
Stack Trace:
_______________________________
gosh> (quote c)
c
gosh> 'c
c
gosh>
                 31
quote

gosh> (x y z)
*** ERROR: unbound variable: y
Stack Trace:
_________________________________
gosh> '(x y z)
(x y z)
gosh> (append '(a b) '(c d))
(a b c d)
gosh>
                 32
S

gosh> (car '(a b c))
a
gosh> (cdr '(a b c))
(b c)
gosh> (cons 'a '(b c))
(a b c)
gosh>


                 33
gosh>
(define (fact n)
  (if (= n 0)
      1
      (* n (fact (- n 1)))))
fact
gosh> (fact 3)
6
gosh> (fact 10)
3628800
gosh>
                  34
gosh> (define sample
'(html
 (body
   (h1 "Lisp")
   (table
     (tr (td 1) (td "lisp"))
     (tr (td 2) (td "scheme"))))))
sample
gosh> (print-html sample)
<html><body><h1>Lisp</h1><table><tr><td>1</td><td>lisp</
td></tr><tr><td>2</td><td>scheme</td></tr></table></
body></html>#<undef>
gosh>
                           35
36
(define (print-html e)
  (if (list? e)
      (begin
       (format #t "<~a>" (car e))
	      (print-html-list   (cdr e))
	      (format #t "</~a>" (car e)))
      (display e)))




                   37
(define (print-html-list l)
  (if (null? l)
      #f
      (begin
       (print-html (car l))
	      (print-html-list (cdr l)))))




                   38
(define (print-html-list l)
  (until (null? l)
    (print-html (car l))
    (set! l (cdr l))))




                   39
Lisp



       http://www.flickr.com/photos/dust/3603580129/ (CC Attribution)


        40
41
> (if (not (= 0 1))
       (print "not-eq")
       (print "eq"))
not-eq
> (not-if (= 0 1)
       (print "not-eq")
       (print "eq"))
not-eq

                    42
(define-macro (not-if test then else)
  (list 'if (list 'not test) then else))


gosh> (not-if (= 0 1) (print "not-eq") (print "eq"))
not-eq
#<undef>
gosh> (not-if (= 0 0) (print "not-eq") (print "eq"))
eq
#<undef>

                         43
(define-macro (not-if test then else)
  (list 'if (list 'not test) then else))

> (let ((test '(= 0 1))
        (then '(print "not-eq"))
        (else '(print "eq")))
   (list 'if (list 'not test) then else))

(if (not (= 0 1)) (print "not-eq") (print "eq"))
                        44
(define-macro (not-if test then else)
  `(if (not ,test) ,then ,else)


 gosh> (let ((a 2) (b 3))
         `(add ,a (sub 5 ,(+ b 1))))
 (add 2 (sub 5 4))
 gosh>

                         45
DSL

(define-action index
  (set! @todos (find <todo> :all)))

(define-action show
  (set! @todo (find <todo> (params :id))))

(define-action edit
  (set! @todo (find <todo> (params :id)))
  (define-continuation edit
   (when (update_attributes @todo (params :todo))
     (flash :notice "todo was successfully updated.")
     (redirect :action 'index))))


                             46
Lisp




       47
REPL




 48
eval (        )




         49
env (        )




        50
51
gosh>   (define (add2 n) (+ n 2))
add2
gosh>   (add2 3)
5
gosh>   (define add2 (lambda(n) (+ n 2)))
add2
gosh>   (add2 3)
5
gosh>

                          52
Lisp




       53
54
http://www.flickr.com/photos/dust/3603580129/ (CC Attribution)




2.1
       55

Más contenido relacionado

La actualidad más candente

Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)
Sean Krail
 
はじめてでもわかるベイズ分類器 -基礎からMahout実装まで-
はじめてでもわかるベイズ分類器 -基礎からMahout実装まで-はじめてでもわかるベイズ分類器 -基礎からMahout実装まで-
はじめてでもわかるベイズ分類器 -基礎からMahout実装まで-
Naoki Yanai
 
証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議
Hiroki Mizuno
 
Single-Loop Software Architecture for JPEG 2000
Single-Loop Software Architecture for JPEG 2000Single-Loop Software Architecture for JPEG 2000
Single-Loop Software Architecture for JPEG 2000
David Bařina
 
Isec2012 o hara
Isec2012 o haraIsec2012 o hara
Isec2012 o hara
Bob O'Hara
 

La actualidad más candente (12)

Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)
 
Understanding Garbage Collection Using Automatic Memory Management
Understanding Garbage Collection Using Automatic Memory ManagementUnderstanding Garbage Collection Using Automatic Memory Management
Understanding Garbage Collection Using Automatic Memory Management
 
Java Script Overview
Java Script OverviewJava Script Overview
Java Script Overview
 
はじめてでもわかるベイズ分類器 -基礎からMahout実装まで-
はじめてでもわかるベイズ分類器 -基礎からMahout実装まで-はじめてでもわかるベイズ分類器 -基礎からMahout実装まで-
はじめてでもわかるベイズ分類器 -基礎からMahout実装まで-
 
Clojure from ground up
Clojure from ground upClojure from ground up
Clojure from ground up
 
証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議
 
Single-Loop Software Architecture for JPEG 2000
Single-Loop Software Architecture for JPEG 2000Single-Loop Software Architecture for JPEG 2000
Single-Loop Software Architecture for JPEG 2000
 
Integralion Formulae 1
Integralion Formulae 1Integralion Formulae 1
Integralion Formulae 1
 
Isec2012 o hara
Isec2012 o haraIsec2012 o hara
Isec2012 o hara
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
La R Users Group Survey Of R Graphics
La R Users Group Survey Of R GraphicsLa R Users Group Survey Of R Graphics
La R Users Group Survey Of R Graphics
 
Radare2 @ ndh2k15 : First r2babies steps
Radare2 @ ndh2k15 : First r2babies stepsRadare2 @ ndh2k15 : First r2babies steps
Radare2 @ ndh2k15 : First r2babies steps
 

Similar a Lisp Primer Key

Lisp for Python Programmers
Lisp for Python ProgrammersLisp for Python Programmers
Lisp for Python Programmers
Vsevolod Dyomkin
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
Databricks
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議
dico_leque
 
CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogramming
dudarev
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

Similar a Lisp Primer Key (20)

Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
AutoDesk
AutoDeskAutoDesk
AutoDesk
 
Lisp for Python Programmers
Lisp for Python ProgrammersLisp for Python Programmers
Lisp for Python Programmers
 
R/C++ talk at earl 2014
R/C++ talk at earl 2014R/C++ talk at earl 2014
R/C++ talk at earl 2014
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Hadoop I/O Analysis
Hadoop I/O AnalysisHadoop I/O Analysis
Hadoop I/O Analysis
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
 
LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийLISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола Мозговий
 
SLIME
SLIMESLIME
SLIME
 
GC in Ruby. RubyC, Kiev, 2014.
GC in Ruby. RubyC, Kiev, 2014.GC in Ruby. RubyC, Kiev, 2014.
GC in Ruby. RubyC, Kiev, 2014.
 
Automated Spark Deployment With Declarative Infrastructure
Automated Spark Deployment With Declarative InfrastructureAutomated Spark Deployment With Declarative Infrastructure
Automated Spark Deployment With Declarative Infrastructure
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
 
Introduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculusIntroduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculus
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in R
 
CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogramming
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Profiling Ruby
Profiling RubyProfiling Ruby
Profiling Ruby
 
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
 

Más de Yuumi Yoshida

新人教育に もっと Rubyを!
新人教育に もっと Rubyを!新人教育に もっと Rubyを!
新人教育に もっと Rubyを!
Yuumi Yoshida
 
流行るLisp用Webフレームワーク(Gauche on Railsから学んだ事)
流行るLisp用Webフレームワーク(Gauche on Railsから学んだ事)流行るLisp用Webフレームワーク(Gauche on Railsから学んだ事)
流行るLisp用Webフレームワーク(Gauche on Railsから学んだ事)
Yuumi Yoshida
 
6年前に作ったプログラムにテストコードを書きました ^^); 〜〜 テスト駆動開発の薦め
6年前に作ったプログラムにテストコードを書きました ^^); 〜〜 テスト駆動開発の薦め6年前に作ったプログラムにテストコードを書きました ^^); 〜〜 テスト駆動開発の薦め
6年前に作ったプログラムにテストコードを書きました ^^); 〜〜 テスト駆動開発の薦め
Yuumi Yoshida
 

Más de Yuumi Yoshida (13)

今さら聞けないAWS on Rails
今さら聞けないAWS on Rails今さら聞けないAWS on Rails
今さら聞けないAWS on Rails
 
EvernoteAPI入門
EvernoteAPI入門EvernoteAPI入門
EvernoteAPI入門
 
新人教育に もっと Rubyを!
新人教育に もっと Rubyを!新人教育に もっと Rubyを!
新人教育に もっと Rubyを!
 
More rubyeducation
More rubyeducationMore rubyeducation
More rubyeducation
 
Grand centraldispatch
Grand centraldispatchGrand centraldispatch
Grand centraldispatch
 
教育というお仕事
教育というお仕事教育というお仕事
教育というお仕事
 
Gaucheを使った簡易出版システム
Gaucheを使った簡易出版システムGaucheを使った簡易出版システム
Gaucheを使った簡易出版システム
 
Nu program language on Shibuya.lisp#5 LT
Nu program language on  Shibuya.lisp#5 LTNu program language on  Shibuya.lisp#5 LT
Nu program language on Shibuya.lisp#5 LT
 
ObjectiveResource
ObjectiveResourceObjectiveResource
ObjectiveResource
 
流行るLisp用Webフレームワーク(Gauche on Railsから学んだ事)
流行るLisp用Webフレームワーク(Gauche on Railsから学んだ事)流行るLisp用Webフレームワーク(Gauche on Railsから学んだ事)
流行るLisp用Webフレームワーク(Gauche on Railsから学んだ事)
 
Ruby on Rails導入に付いて
Ruby on Rails導入に付いてRuby on Rails導入に付いて
Ruby on Rails導入に付いて
 
6年前に作ったプログラムにテストコードを書きました ^^); 〜〜 テスト駆動開発の薦め
6年前に作ったプログラムにテストコードを書きました ^^); 〜〜 テスト駆動開発の薦め6年前に作ったプログラムにテストコードを書きました ^^); 〜〜 テスト駆動開発の薦め
6年前に作ったプログラムにテストコードを書きました ^^); 〜〜 テスト駆動開発の薦め
 
Rails南蛮通事
Rails南蛮通事Rails南蛮通事
Rails南蛮通事
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Lisp Primer Key

  • 2. 2
  • 3. 2000 EY-Office 3
  • 4. 4
  • 5. Lisp 5
  • 6. New York “The lisps” Sammy Tunis flickr ”lisp” http://www.flickr.com/photos/dust/3603580129/ (CC Attribution) 6
  • 7. Lisp S Lisp (Lisp ) 7
  • 8. Lisp http://www.flickr.com/photos/dust/3603580129/ (CC Attribution) 8
  • 9. Lisp LL 1960 1970 1980 1990 2000 FORTAN C C++ Java C# ALGOL Pascal Simula COBOL Lisp1.5 Common Lisp Scheme Perl Ruby Smalltalk Python Javascript Haskell Prolog 9
  • 10. Lisp Perl,Ruby,Python, Javascript ... Java,Perl,Ruby, Python, Javascript ... (Lisp) Haskell,Scale (Ruby, Javascript...) !? !? 10
  • 11. 11
  • 13. 13
  • 15. 15
  • 16. S http://www.flickr.com/photos/dust/3603580129/ (CC Attribution) 16
  • 17. S 17
  • 18. S 18
  • 19. S 19
  • 20. S 20
  • 21. S 21
  • 22. S 22
  • 23. 23
  • 24. 24
  • 25. Lisp http://www.flickr.com/photos/dust/3603580129/ (CC Attribution) 25
  • 26. % rlwrap gosh gosh> (+ 1 2) 3 gosh> (* 2 (+ 3 4)) 14 gosh> 26
  • 27. gosh> (define a 3) a gosh> a 3 gosh> (define b (+ 2 5)) b gosh> b 7 gosh> (+ a b) 10 27
  • 28. gosh> (set! a (+ a 1)) 4 gosh> a 4 gosh> c *** ERROR: unbound variable: c gosh> 28
  • 29. gosh> (let ((a 2) (b 3)) (set! a (+ a 1)) (+ a b)) 6 gosh> 29
  • 30. gosh> (define (add3 n) (+ n 3)) add3 gosh> (add3 5) 8 gosh> (add3 (add3 4)) 10 30
  • 31. quote gosh> c *** ERROR: unbound variable: c Stack Trace: _______________________________ gosh> (quote c) c gosh> 'c c gosh> 31
  • 32. quote gosh> (x y z) *** ERROR: unbound variable: y Stack Trace: _________________________________ gosh> '(x y z) (x y z) gosh> (append '(a b) '(c d)) (a b c d) gosh> 32
  • 33. S gosh> (car '(a b c)) a gosh> (cdr '(a b c)) (b c) gosh> (cons 'a '(b c)) (a b c) gosh> 33
  • 34. gosh> (define (fact n) (if (= n 0) 1 (* n (fact (- n 1))))) fact gosh> (fact 3) 6 gosh> (fact 10) 3628800 gosh> 34
  • 35. gosh> (define sample '(html (body (h1 "Lisp") (table (tr (td 1) (td "lisp")) (tr (td 2) (td "scheme")))))) sample gosh> (print-html sample) <html><body><h1>Lisp</h1><table><tr><td>1</td><td>lisp</ td></tr><tr><td>2</td><td>scheme</td></tr></table></ body></html>#<undef> gosh> 35
  • 36. 36
  • 37. (define (print-html e) (if (list? e) (begin (format #t "<~a>" (car e)) (print-html-list (cdr e)) (format #t "</~a>" (car e))) (display e))) 37
  • 38. (define (print-html-list l) (if (null? l) #f (begin (print-html (car l)) (print-html-list (cdr l))))) 38
  • 39. (define (print-html-list l) (until (null? l) (print-html (car l)) (set! l (cdr l)))) 39
  • 40. Lisp http://www.flickr.com/photos/dust/3603580129/ (CC Attribution) 40
  • 41. 41
  • 42. > (if (not (= 0 1)) (print "not-eq") (print "eq")) not-eq > (not-if (= 0 1) (print "not-eq") (print "eq")) not-eq 42
  • 43. (define-macro (not-if test then else) (list 'if (list 'not test) then else)) gosh> (not-if (= 0 1) (print "not-eq") (print "eq")) not-eq #<undef> gosh> (not-if (= 0 0) (print "not-eq") (print "eq")) eq #<undef> 43
  • 44. (define-macro (not-if test then else) (list 'if (list 'not test) then else)) > (let ((test '(= 0 1)) (then '(print "not-eq")) (else '(print "eq"))) (list 'if (list 'not test) then else)) (if (not (= 0 1)) (print "not-eq") (print "eq")) 44
  • 45. (define-macro (not-if test then else) `(if (not ,test) ,then ,else) gosh> (let ((a 2) (b 3)) `(add ,a (sub 5 ,(+ b 1)))) (add 2 (sub 5 4)) gosh> 45
  • 46. DSL (define-action index (set! @todos (find <todo> :all))) (define-action show (set! @todo (find <todo> (params :id)))) (define-action edit (set! @todo (find <todo> (params :id))) (define-continuation edit (when (update_attributes @todo (params :todo)) (flash :notice "todo was successfully updated.") (redirect :action 'index)))) 46
  • 47. Lisp 47
  • 49. eval ( ) 49
  • 50. env ( ) 50
  • 51. 51
  • 52. gosh> (define (add2 n) (+ n 2)) add2 gosh> (add2 3) 5 gosh> (define add2 (lambda(n) (+ n 2))) add2 gosh> (add2 3) 5 gosh> 52
  • 53. Lisp 53
  • 54. 54