Prgišče Lispa

  • 545 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
545
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
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. Prgišče lispa [email_address]
  • 2. Delovno okolje
    • Common Lisp
    • SBCL [http:// sbcl.org ]
    • CL HyperSpec [ http://bit.ly/2l00Sw ]
  • 3. Funkcijsko programiranje
    • Abstrakcije pogostih operacij
      • Rekurzija, iteracija, filtriranje, ...
    • Funkcije kot parametri
      • Kombiniranje funkcij
    • Konstrukcija/dekonstrukcija podatkovnih struktur
      • rekurzija
      • Map-reduce
  • 4. Temeljne podatkovne strukture
  • 5. Atomi
    • a
    • ‘ a = (quote a)
    • #’foo = (function foo)
    • nil = ‘()
  • 6. cons
    • (cons ‘a ‘b) = ‘(a . b)
    • (cons ‘a nil) = (list ‘a) = ‘(a)
    • (list ‘a ‘b ‘c) = (cons ‘a
    • (cons ‘b
    • (cons‘c nil)))
    • = ‘(a b c)
  • 7. (De-)konstrukcija consa
    • (first ‘(a . b)) => ‘a
    • (rest ‘(a . b)) => ‘b
    • (rest ‘(a b)) => ‘(b)
    • (rest ‘(a b c)) => ‘(b c)
    • rekurzija
  • 8. Primer: map
    • (defun my-map (fn xs)
    • (if (null xs)
    • nil
    • (cons (funcall fn (first xs))
    • (my-map fn (rest xs)))))
  • 9. Tail-call optimizacija
    • (defun my-map2 (fn xs acc)
    • (if (null xs)
    • (reverse acc)
    • (my-map2 fn (rest xs)
    • (cons (funcall fn (first xs)) acc))))
  • 10. Abstrakcija iteracije
    • (defun my-map3 (fn xs)
    • (reverse
    • (reduce (lambda (acc x)
    • (cons (funcall fn x) acc))
    • xs)))
  • 11.
    • '(poetika
    • ((profano
      • (pripovedništvo
      • (dramatika
      • (tragedija komedija opera)) slikarstvo))
      • sakralno))
    Drevesa poetika sakralno profano pripovedništvo slikarstvo dramatika opera komedija tragedija
  • 12.
    • (defun count-nodes (tree)
    • (if (consp tree)
    • (reduce ( function +)
    • (mapcar (function count-nodes) tree))
    • 1))
    opera komedija tragedija poetika sakralno profano pripovedništvo slikarstvo dramatika 1 1 1 1 1 1 1 1 1 3 6 7 9 4 8
  • 13. Homoikoničnost koda = podatek
  • 14. Makri
    • Prevajanje kode v kodo
      • Pisanje prevajalnikov kot splošno orodje
    • Compile-time v. Run-time
  • 15. Bottom-up programiranje Vaja
  • 16.  x
    • (defun sum (xs)
    • (reduce #'+ xs :initial-value 0))
    • (defun reduce (fn xs &key initial-value
    • (start 0))
    • ...)
  • 17.  f(x)
    • (defun sum (fn xs)
    • (reduce #'+
    • (map 'vector fn xs)
    • :initial-value 0))
  • 18.  f(x 1 , x 2 , ..., x n )
    • (defun sum (fn &rest xs)
    • (reduce #'+
    • (apply #'map 'vector fn xs)
    • :initial-value 0))
    • (apply #'+ 1 2 '(3 4 5 )) => (+ 1 2 3 4 5 )
  • 19. L 2 norma
    • (defun ^2 (x)
    • (expt x 2))
    • (defun l2-norm (xs)
    • (sqrt (sum #'^2 xs)))
  • 20. Namesto domače naloge