Your SlideShare is downloading. ×
Prgišče Lispa
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Prgišče Lispa

561
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
561
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
1
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