XMonad-oid on Emacs & More functional Emacs Lisp | 関数型LT大会

Embed Size (px)

DESCRIPTION

関数型LT大会 @クックパッド, 東京 2014/05/11 の発表スライドです.

Text of XMonad-oid on Emacs & More functional Emacs Lisp | 関数型LT大会

  • 1. XMonad-oid on Emacs & More functional Emacs Lisp (keno)

2. (keno, Twitter: @keno_ss) Lisper, Schemer Haskell () Emacs Lisp Emacs Lisp 3. ()Emacs Lisp ewm.el (EmacsWMonad; XMonod-oid on Emacs) debug-print.el (Gauches nice printf-debugging) ERFI (SRFI in Emacs Lisp) hairs.el (Haskell influenced record syntax) R7RSdefine-library () 4. XMonad-oid on Emacs ewm.el More functional Emacs Lisp ERFI hairs.el 5. XMonad-oid on Emacs 6. () 7. 8. More functional Emacs Lisp 9. Lisp? Lisp No (by Let Over Lambda). Scheme Maybe yes. Common Lisp CLer? (Common Lisp ) 10. Emacs Lisp? Definitely no. dynamic binding (not lexical binding) let lambda Emacs LispCLLisp (cl.el) (CL) while CL loop do-times append-map! (mapcon) append-map 11. (emacs 24.3) lexical-binding closure ! (>= 24) cl.el cl-lib.el () cl.el gv.el (generalized variables; )() pcase.el (ML-style pattern-matching macro for Elisp) . . 12. () 13. ERFI () SchemeSRFI(+Gauche)Emacs( )() SRFI 1: SRFI 2 26 61 67: and-let* cut cute cond case ecase SRFI 5: let, Elisp CL ! 14. named let + 15. (defun fact-slow (n) ; (if (zerop n) 1 (* n (fact-slow (- n 1))))) (defun fact/tco (n) ; (fact-aux n 1)) (defun fact-aux (n r) (if (zerop n) r (fact-aux (- n 1) (* r n)))) (defun fact (n) ; let (let iter (n r) (if (zerop n) r (iter (- n 1) (* r n)))) 16. Emacs Lisp2004 GNU. (Oliver Scholz, tail recursion hack in Emacs Lisp?) 2013 nlet.el . () (unwind) Emacs (, Emacs Lisp , ) : Emacs . 17. Scholz nlet.el while (nlet.el) progn funcall mapcar 18. erfi:let SRFI 5 (named let) R5RS Scholz nlet.el bug 19. (defun fact (n) (erfi:let iter ((n 5) (r 1)) (if (zerop n) r (iter (1- n) (* r n))))) (defun fact (n) (let ((--erfi-continue-- t) (--erfi-result-- nil) (G4201 n) (G4202 1) (n nil) (r nil)) (while --erfi-continue-- (setq n G4201) (setq r G4202) (catch '--erfi-repeat-- (setq --erfi-result-- (if (zerop n) r (progn (setq G4201 (1- n)) (setq G4202 (* r n)) (throw '--erfi-repeat-- nil)))) (setq --erfi-continue-- nil))) --erfi-result--) 20. : (defun erfi:list= (elt= &rest xss) (if (let1 len (length (car xss)) (not (erfi:every1 (lambda (xs) (eq len (length xs))) (cdr xss)))) nil (erfi:let outer-iter ((xss xss)) (if (null (cdr xss)) t (erfi:let inner-iter ((xs (car xss)) (ys (cadr xss))) (if (null xs) (outer-iter (cdr xss)) (and (funcall elt= (car xs) (car ys)) (inner-iter (cdr xs) (cdr ys))))))))) macroexpand while 21. Haskell 22. Haskell (()Haskell) (() ( ( ()) )) LispHaskell Gauche $ Lisp!! (Haskeller) 23. data Person = Person { firstName :: String , lastName :: String , age :: Int , phoneNumber :: String } deriving (Show) data Book = Book { author :: Person , title :: String , price :: Int } derivin (Show) let author = Person "Saunders" "MacLane" 30 "unknown" let book = Book author "Categories for the Working Mathematician" 8500 book { author : author book { lastName : "Mac Lane" , age : 95 , phoneNumber : "unknown" } , price : 3000 }() ! 24. Emacs Lisp XMonad-oid on Emacs() evm-util.el (2013) hairs.el (2014) 25. ewm-util.el cl.el () cl.el getter setter setf () () 26. hairs.el (Haskell influenced record syntax) Lisp DSL () alist, plist, hash-table, array, struct, eieio (CLOS) 27. (hairs-copy '((:hoge . hoge) (:fuga . fuga) (:foo . foo) (:bar . (:john "Smith" :jane "Smith"))) (with :alist :hoge 'hogehoge :foo => (lambda (x) (list x x)) :bar (with :plist :john "Hi" :jane "Hello"))) '((:hoge . hogehoge) (:fuga . fuga) (:foo . (foo foo)) (:bar . (:john "Hi" :jane "Hello"))) 28. (cl-defstruct hairs:person name age sex) (cl-defstruct hairs:group name description member) (hairs-register-type '((:struct hairs:group) member) '(:alist (:struct hairs:person))) (with (:struct hairs:group) :member (with :alist b (with (:struct hairs:person) :name "Neo"))) (with (:struct hairs:group) :member (w/ b (w/ :name "Neo"))) 29. Any questions or comments? Twitter: @keno_ss GitHub: https://github.com/kenoss () , , pull-req 30. Twitter: @keno_ss GitHub: https://github.com/kenoss () , , pull-req