inf4820 algorithms for artificial intelligence and
play

INF4820: Algorithms for Artificial Intelligence and Natural - PowerPoint PPT Presentation

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing More Common Lisp Stephan Oepen & Murhaf Fares Language Technology Group (LTG) September 6, 2017 Agenda Previously Common Lisp essentials


  1. INF4820: Algorithms for Artificial Intelligence and Natural Language Processing More Common Lisp Stephan Oepen & Murhaf Fares Language Technology Group (LTG) September 6, 2017

  2. Agenda Previously ◮ Common Lisp essentials ◮ S-expressions ( = atoms or lists of s-expressions) ◮ Recursion ◮ Quote ◮ List processing ◮ Identity vs. Equality 2

  3. Agenda Previously ◮ Common Lisp essentials ◮ S-expressions ( = atoms or lists of s-expressions) ◮ Recursion ◮ Quote ◮ List processing ◮ Identity vs. Equality Today ◮ More Common Lisp ◮ Higher-order functions ◮ Argument lists ◮ Iteration: (the mighty) loop ◮ Additional data structures 2

  4. Conditional Evaluation Examples ? (defparameter foo 42) ? (if (numberp foo) "number" "something else") 3

  5. Conditional Evaluation Examples ? (defparameter foo 42) ? (if (numberp foo) "number" "something else") → "number" 3

  6. Conditional Evaluation Examples ? (defparameter foo 42) ? (if (numberp foo) "number" "something else") → "number" ? (cond ((< foo 3) "less") ((> foo 3) "more") (t "equal")) 3

  7. Conditional Evaluation Examples ? (defparameter foo 42) ? (if (numberp foo) "number" "something else") → "number" ? (cond ((< foo 3) "less") ((> foo 3) "more") (t "equal")) → "more" 3

  8. Conditional Evaluation Examples General Form ? (defparameter foo 42) (if � predicate � ? (if (numberp foo) � then clause � "number" � else clause � ) "something else") → "number" (cond ( � predicate 1 � � clause 1 � + ) ? (cond ((< foo 3) "less") ( � predicate 2 � � clause 2 � + ) ((> foo 3) "more") ( � predicate i � � clause i � + ) (t "equal")) (t � default clause � + )) → "more" 3

  9. Rewind: A Note on Symbol Semantics ◮ Symbols can have values as functions and variables at the same time. ◮ #’ ( sharp-quote ) gives us the function object bound to a symbol. ? (defun foo (x) (* x 1000)) 4

  10. Rewind: A Note on Symbol Semantics ◮ Symbols can have values as functions and variables at the same time. ◮ #’ ( sharp-quote ) gives us the function object bound to a symbol. ? (defun foo (x) (* x 1000)) ? (defparameter foo 42) → 42 4

  11. Rewind: A Note on Symbol Semantics ◮ Symbols can have values as functions and variables at the same time. ◮ #’ ( sharp-quote ) gives us the function object bound to a symbol. ? (defun foo (x) (* x 1000)) ? (defparameter foo 42) → 42 ? (foo foo) → 4

  12. Rewind: A Note on Symbol Semantics ◮ Symbols can have values as functions and variables at the same time. ◮ #’ ( sharp-quote ) gives us the function object bound to a symbol. ? (defun foo (x) (* x 1000)) ? (defparameter foo 42) → 42 ? (foo foo) → 42000 4

  13. Rewind: A Note on Symbol Semantics ◮ Symbols can have values as functions and variables at the same time. ◮ #’ ( sharp-quote ) gives us the function object bound to a symbol. ? (defun foo (x) (* x 1000)) ? (defparameter foo 42) → 42 ? (foo foo) → 42000 ? foo → 42 4

  14. Rewind: A Note on Symbol Semantics ◮ Symbols can have values as functions and variables at the same time. ◮ #’ ( sharp-quote ) gives us the function object bound to a symbol. ? (defun foo (x) (* x 1000)) ? (defparameter foo 42) → 42 ? (foo foo) → 42000 ? foo → 42 ? #’foo → #<Interpreted Function FOO> 4

  15. Rewind: A Note on Symbol Semantics ◮ Symbols can have values as functions and variables at the same time. ◮ #’ ( sharp-quote ) gives us the function object bound to a symbol. ? (defun foo (x) (* x 1000)) ? (defparameter foo 42) → 42 ? (foo foo) → 42000 ? foo → 42 ? #’foo → #<Interpreted Function FOO> ? (funcall #’foo foo) → 42000 4

  16. Rewind: A Note on Symbol Semantics ◮ Symbols can have values as functions and variables at the same time. ◮ #’ ( sharp-quote ) gives us the function object bound to a symbol. ? (defun foo (x) (* x 1000)) ? (defparameter foo 42) → 42 ? (foo foo) → 42000 ? foo → 42 ? #’foo → #<Interpreted Function FOO> ? (funcall #’foo foo) → 42000 ◮ #’ and funcall (as well as apply ) are useful when passing around functions as arguments. 4

  17. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. 5

  18. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) 5

  19. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) 5

  20. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) ? (defparameter foo ’(11 22 33 44 55)) 5

  21. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) ? (defparameter foo ’(11 22 33 44 55)) ? (filter foo #’evenp) 5

  22. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) ? (defparameter foo ’(11 22 33 44 55)) ? (filter foo #’evenp) → (22 44) 5

  23. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) ? (defparameter foo ’(11 22 33 44 55)) ? (filter foo #’evenp) → (22 44) ◮ Functions 5

  24. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) ? (defparameter foo ’(11 22 33 44 55)) ? (filter foo #’evenp) → (22 44) ◮ Functions, recursion 5

  25. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) ? (defparameter foo ’(11 22 33 44 55)) ? (filter foo #’evenp) → (22 44) ◮ Functions, recursion, conditionals 5

  26. Higher-Order Functions ◮ Functions that accept functions as arguments or return values. ◮ Functions in Lisp are first-class objects. ◮ Can be created at run-time, passed as arguments, returned as values, stored in variables . . . just like any other type of data. ? (defun filter (list test) (cond ((null list) nil) ((funcall test (first list)) (cons (first list) (filter (rest list) test))) (t (filter (rest list) test)))) ? (defparameter foo ’(11 22 33 44 55)) ? (filter foo #’evenp) → (22 44) ◮ Functions, recursion, conditionals, predicates 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend