Your SlideShare is downloading. ×
PAIP 第1章 Lisp入門
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

PAIP 第1章 Lisp入門

1,269
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,269
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide




















  • Transcript

    • 1. PAIP 1 Lisp yadokarielectric | yad-EL
    • 2. • 1.10 • 1 • • 1
    • 3. •1 1 • 1 1 • 1 1 • •
    • 4. • • OK •
    • 5. • • • Lisp
    • 6. • Lisp •( 1 2 …) • • (+ 1 (* 2 3 4) 5)
    • 7. • • • (if then else ) • if then elese
    • 8. • • setf • (setf abc 3)
    • 9. • • • • 2 2
    • 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)))

    ×