SlideShare ist ein Scribd-Unternehmen logo
1 von 20
PAIP   1        Lisp

           yadokarielectric | yad-EL
•       1.10

•   1

•
•              1
•1       1

•    1       1

•    1
     1

•
•
•
•
    OK

•
•

•
• Lisp
• Lisp
•(               1       2 …)

•

•    (+ 1 (* 2 3 4) 5)
•

•
• (if       then   else )

• if                        then
    elese
•

•
    setf

• (setf abc 3)
•
•
•
•
    2   2
• (setf x (1 2 3))
                        (1 2 3)
     1



•            (setf x (list 1 2 3))
quote
•
     quote

• (setf x (quote (1 2 3)))
•             '

• (setf x '(1 2 3))
(setf p '(JOHN Q PUBLIC))
•   (first p)           •    (cons 'Mr p)

•   (rest p)           •    (cons (first p) (rest p))

•   (second p)         •    (last p)

•   (third p)          •    (first (last p))

•   (fourth p)

•   (length p)
•          defun

• (defun     (     1   2…)

    "                        "

             …)
•

•              mapcar

•
    function             #'

• (mapcar #'last-name names)
1.1

(defparameter *suffix*
 '(MD Jr. |,|))

(defun last-name (name)
 (if (member (first (last name)) *suffix*)
     (last-name (butlast name))
     (first (last name))))
n=28
     1.2
                                              loop-power   27

                                              power
(defun loop-power (x n)
 (let ((r 1))                                 28 2
   (dotimes (i n)                             14 2
     (setf r (* r x)))                        7 x
   r))                                        6   2
                                              3 x
(defun square (x) (* x x))
                                              2   2
(defun power (x n)
                                                     6
 (cond ((= n 0) 1)
     ((evenp n) (square (power x (/ n 2))))
     (t (* x (power x (- n 1))))))
1.3   nil


(defun count-atoms (exp)
 (cond ((null exp) 0)
     ((atom exp) 1)
     (t (+ (count-atoms (first exp))
          (count-atoms (rest exp))))))
1.3   nil

(defun count-all-atoms (exp &optional (if-null 1))
 (cond ((null exp) if-null)
     ((atom exp) 1)
     (t (+ (count-all-atoms (first exp) 1)
          (count-all-atoms (rest exp) 0)))))
1.4

(defun count-anywhere (item tree)
 (cond ((eql item tree) 1)
     ((atom tree) 0)
     (t (+ (count-anywhere item (first tree))
          (count-anywhere item (rest tree))))))
1.5
(defun dot-product (a b)
 (if (or (null a) (null b))
     0
     (+ (* (first a) (first b))
       (dot-product (rest a) (rest b)))))

(defun dot-product (a b)
 (let ((sum 0))
   (dotimes (i (length a))
    (incf sum (* (elt a i) (elt b i))))
   sum))

(defun dot-product (a b)
 (apply #'+ (mapcar #'* a b)))

Weitere ähnliche Inhalte

Was ist angesagt?

Day 5 examples u6w14
Day 5 examples u6w14Day 5 examples u6w14
Day 5 examples u6w14
jchartiersjsd
 
119 Powerpoint 2.6
119 Powerpoint 2.6119 Powerpoint 2.6
119 Powerpoint 2.6
Jeneva Clark
 
Operations on Functions
Operations on FunctionsOperations on Functions
Operations on Functions
swartzje
 

Was ist angesagt? (20)

Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics Using R Tool for Probability and Statistics
Using R Tool for Probability and Statistics
 
Day 6 examples
Day 6 examplesDay 6 examples
Day 6 examples
 
04. haskell handling
04. haskell handling04. haskell handling
04. haskell handling
 
The secrets of inverse brogramming
The secrets of inverse brogrammingThe secrets of inverse brogramming
The secrets of inverse brogramming
 
Day 5 examples u6w14
Day 5 examples u6w14Day 5 examples u6w14
Day 5 examples u6w14
 
119 Powerpoint 2.6
119 Powerpoint 2.6119 Powerpoint 2.6
119 Powerpoint 2.6
 
脳の計算論 第3章「リズム活動と位相応答」
脳の計算論 第3章「リズム活動と位相応答」脳の計算論 第3章「リズム活動と位相応答」
脳の計算論 第3章「リズム活動と位相応答」
 
Clojure night
Clojure nightClojure night
Clojure night
 
Families of Triangular Norm Based Kernel Function and Its Application to Kern...
Families of Triangular Norm Based Kernel Function and Its Application to Kern...Families of Triangular Norm Based Kernel Function and Its Application to Kern...
Families of Triangular Norm Based Kernel Function and Its Application to Kern...
 
SPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta MethodsSPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta Methods
 
Day 4 examples
Day 4 examplesDay 4 examples
Day 4 examples
 
Lesson 51
Lesson 51Lesson 51
Lesson 51
 
Day 3 examples
Day 3 examplesDay 3 examples
Day 3 examples
 
Day 1 examples
Day 1 examplesDay 1 examples
Day 1 examples
 
Cheat sheet python3
Cheat sheet python3Cheat sheet python3
Cheat sheet python3
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 
chap 2 Ex#1.1
chap 2 Ex#1.1chap 2 Ex#1.1
chap 2 Ex#1.1
 
Day 5 examples
Day 5 examplesDay 5 examples
Day 5 examples
 
Operations on Functions
Operations on FunctionsOperations on Functions
Operations on Functions
 
Addition and Subtraction of Functions
Addition and Subtraction of FunctionsAddition and Subtraction of Functions
Addition and Subtraction of Functions
 

Andere mochten auch (8)

Serverspecを使ってみた話
Serverspecを使ってみた話Serverspecを使ってみた話
Serverspecを使ってみた話
 
Start Haskell - Exercise 13 1
Start Haskell - Exercise 13 1Start Haskell - Exercise 13 1
Start Haskell - Exercise 13 1
 
PAIP 第5章 ELIZA
PAIP 第5章 ELIZAPAIP 第5章 ELIZA
PAIP 第5章 ELIZA
 
Phoenixを使った案件でリリースまでに起きた問題と対応
Phoenixを使った案件でリリースまでに起きた問題と対応Phoenixを使った案件でリリースまでに起きた問題と対応
Phoenixを使った案件でリリースまでに起きた問題と対応
 
running web app on elixir
running web app on elixirrunning web app on elixir
running web app on elixir
 
Elixir lang bootstrap
Elixir lang bootstrapElixir lang bootstrap
Elixir lang bootstrap
 
Erlangご紹介 websocket編
Erlangご紹介 websocket編Erlangご紹介 websocket編
Erlangご紹介 websocket編
 
機械学習概論 講義テキスト
機械学習概論 講義テキスト機械学習概論 講義テキスト
機械学習概論 講義テキスト
 

Ähnlich wie PAIP 第1章 Lisp入門

ฟังก์ชัน(function)
ฟังก์ชัน(function)ฟังก์ชัน(function)
ฟังก์ชัน(function)
Yodhathai Reesrikom
 
ฟังก์ชัน(function)
ฟังก์ชัน(function)ฟังก์ชัน(function)
ฟังก์ชัน(function)
Yodhathai Reesrikom
 
Aaron Ellison Keynote: Reaching the 99%
Aaron Ellison Keynote: Reaching the 99%Aaron Ellison Keynote: Reaching the 99%
Aaron Ellison Keynote: Reaching the 99%
David LeBauer
 
The Magnificent Seven
The Magnificent SevenThe Magnificent Seven
The Magnificent Seven
Mike Fogus
 
Lecture4 kenrels functions_rkhs
Lecture4 kenrels functions_rkhsLecture4 kenrels functions_rkhs
Lecture4 kenrels functions_rkhs
Stéphane Canu
 
Hybrid Atlas Models of Financial Equity Market
Hybrid Atlas Models of Financial Equity MarketHybrid Atlas Models of Financial Equity Market
Hybrid Atlas Models of Financial Equity Market
tomoyukiichiba
 
University of manchester mathematical formula tables
University of manchester mathematical formula tablesUniversity of manchester mathematical formula tables
University of manchester mathematical formula tables
Gaurav Vasani
 
Predictably
PredictablyPredictably
Predictably
ztellman
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errors
maheej
 

Ähnlich wie PAIP 第1章 Lisp入門 (20)

ฟังก์ชัน(function)
ฟังก์ชัน(function)ฟังก์ชัน(function)
ฟังก์ชัน(function)
 
ฟังก์ชัน 1
ฟังก์ชัน 1ฟังก์ชัน 1
ฟังก์ชัน 1
 
ฟังก์ชัน(function)
ฟังก์ชัน(function)ฟังก์ชัน(function)
ฟังก์ชัน(function)
 
Aaron Ellison Keynote: Reaching the 99%
Aaron Ellison Keynote: Reaching the 99%Aaron Ellison Keynote: Reaching the 99%
Aaron Ellison Keynote: Reaching the 99%
 
Zero Theorem and Rational Roots Presentation
Zero Theorem and Rational Roots PresentationZero Theorem and Rational Roots Presentation
Zero Theorem and Rational Roots Presentation
 
The Magnificent Seven
The Magnificent SevenThe Magnificent Seven
The Magnificent Seven
 
Lecture4 kenrels functions_rkhs
Lecture4 kenrels functions_rkhsLecture4 kenrels functions_rkhs
Lecture4 kenrels functions_rkhs
 
1531 fourier series- integrals and trans
1531 fourier series- integrals and trans1531 fourier series- integrals and trans
1531 fourier series- integrals and trans
 
Ecma script 5
Ecma script 5Ecma script 5
Ecma script 5
 
MLP輪読スパース8章 トレースノルム正則化
MLP輪読スパース8章 トレースノルム正則化MLP輪読スパース8章 トレースノルム正則化
MLP輪読スパース8章 トレースノルム正則化
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기
 
Hybrid Atlas Models of Financial Equity Market
Hybrid Atlas Models of Financial Equity MarketHybrid Atlas Models of Financial Equity Market
Hybrid Atlas Models of Financial Equity Market
 
University of manchester mathematical formula tables
University of manchester mathematical formula tablesUniversity of manchester mathematical formula tables
University of manchester mathematical formula tables
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
CQL 实现
CQL 实现CQL 实现
CQL 实现
 
Lambda calculus
Lambda calculusLambda calculus
Lambda calculus
 
Predictably
PredictablyPredictably
Predictably
 
R Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfR Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdf
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errors
 
Seismic data processing lecture 3
Seismic data processing lecture 3Seismic data processing lecture 3
Seismic data processing lecture 3
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

PAIP 第1章 Lisp入門

  • 1. PAIP 1 Lisp yadokarielectric | yad-EL
  • 2. 1.10 • 1 • • 1
  • 3. •1 1 • 1 1 • 1 1 • •
  • 4. • • OK •
  • 6. • Lisp •( 1 2 …) • • (+ 1 (* 2 3 4) 5)
  • 7. • • • (if then else ) • if then elese
  • 8. • • setf • (setf abc 3)
  • 10. • (setf x (1 2 3)) (1 2 3) 1 • (setf x (list 1 2 3))
  • 11. quote • quote • (setf x (quote (1 2 3))) • ' • (setf x '(1 2 3))
  • 12. (setf p '(JOHN Q PUBLIC)) • (first p) • (cons 'Mr p) • (rest p) • (cons (first p) (rest p)) • (second p) • (last p) • (third p) • (first (last p)) • (fourth p) • (length p)
  • 13. defun • (defun ( 1 2…) " " …)
  • 14. • • mapcar • function #' • (mapcar #'last-name names)
  • 15. 1.1 (defparameter *suffix* '(MD Jr. |,|)) (defun last-name (name) (if (member (first (last name)) *suffix*) (last-name (butlast name)) (first (last name))))
  • 16. n=28 1.2 loop-power 27 power (defun loop-power (x n) (let ((r 1)) 28 2 (dotimes (i n) 14 2 (setf r (* r x))) 7 x r)) 6 2 3 x (defun square (x) (* x x)) 2 2 (defun power (x n) 6 (cond ((= n 0) 1) ((evenp n) (square (power x (/ n 2)))) (t (* x (power x (- n 1))))))
  • 17. 1.3 nil (defun count-atoms (exp) (cond ((null exp) 0) ((atom exp) 1) (t (+ (count-atoms (first exp)) (count-atoms (rest exp))))))
  • 18. 1.3 nil (defun count-all-atoms (exp &optional (if-null 1)) (cond ((null exp) if-null) ((atom exp) 1) (t (+ (count-all-atoms (first exp) 1) (count-all-atoms (rest exp) 0)))))
  • 19. 1.4 (defun count-anywhere (item tree) (cond ((eql item tree) 1) ((atom tree) 0) (t (+ (count-anywhere item (first tree)) (count-anywhere item (rest tree))))))
  • 20. 1.5 (defun dot-product (a b) (if (or (null a) (null b)) 0 (+ (* (first a) (first b)) (dot-product (rest a) (rest b))))) (defun dot-product (a b) (let ((sum 0)) (dotimes (i (length a)) (incf sum (* (elt a i) (elt b i)))) sum)) (defun dot-product (a b) (apply #'+ (mapcar #'* a b)))

Hinweis der Redaktion