From d0a2434679e86a207182400a0498ee3b947e8b86 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Tue, 12 Jul 2022 15:53:46 +0100 Subject: [PATCH] Add episode 8 to the videos.org --- docs/videos.org | 69 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/docs/videos.org b/docs/videos.org index 2a68cbd..ff0cdc9 100644 --- a/docs/videos.org +++ b/docs/videos.org @@ -415,7 +415,8 @@ CLOSED: [2022-06-13 Mon 10:38] - https://www.gnu.org/software/emacs/manual/html_node/elisp/Plist-Access.html - https://www.gnu.org/software/emacs/manual/html_node/elisp/Plists-and-Alists.html -* Episode 7 - Basic Loops +* DONE Episode 7 - Basic Loops +CLOSED: [2022-07-09 Sat 10:31] ** About previous episode - Duplicate keys in an association list - ~eval-defun~ @@ -488,4 +489,70 @@ CLOSED: [2022-06-13 Mon 10:38] * Episode 8 - More Loops ** Recursion +- A *Recursive* function, is a function that defines in terms of itself +- Easy to implement +- But should be careful with it to aviod infinit loops + +*** Example +#+BEGIN_SRC emacs-lisp + (defun foo (int) + (print int) + (when (> int 0) + (foo (- int 1)))) + + (foo 10) +#+END_SRC + ** Functional style loops +*** Mapping functions Family +- ~mapcar~ +#+BEGIN_SRC emacs-lisp + (mapcar #'1+ '(1 2 3 4 5)) + + (mapcar (lambda (x) (* x x)) + '(1 2 3 4)) +#+END_SRC + +- ~mapc~ +#+BEGIN_SRC emacs-lisp + (mapc #'1+ '(1 2 3 4 5)) + (mapc #'print '(1 2 3 4 5)) +#+END_SRC + +- ~map-concat~ +#+BEGIN_SRC emacs-lisp + (mapconcat (lambda (x) + (format "[%s]" x)) + '(1 2 3 4 5) + " <|> ") +#+END_SRC + +*** Seq module +A collection of handy functions that operate on ~sequences~. + +- ~seq-reduce~ +#+BEGIN_SRC emacs-lisp + (require 'seq) + + (seq-reduce + + (lambda (acc x) + (+ acc x)) + + '(1 2 3 4) + + 0) +#+END_SRC + +- ~seq-filter~ +#+BEGIN_SRC emacs-lisp + (seq-filter (lambda (x) (< x 10)) + '(8 12 22 9)) +#+END_SRC +- ~seq-partition~ +#+BEGIN_SRC emacs-lisp + (seq-partition '(a b c d e f) 2) + +#+END_SRC +- ~seq-min~, ~seq-max~ +* Episode 9 - Basics of Macros