forked from FG42/FG42
Finish up ep number 9
This commit is contained in:
parent
d0a2434679
commit
a0ad4fc78e
|
@ -487,7 +487,8 @@ CLOSED: [2022-07-09 Sat 10:31]
|
|||
(message ">> %s" x))))
|
||||
#+END_SRC
|
||||
|
||||
* Episode 8 - More Loops
|
||||
* DONE Episode 8 - More Loops
|
||||
CLOSED: [2022-07-29 Fri 15:11]
|
||||
** Recursion
|
||||
- A *Recursive* function, is a function that defines in terms of itself
|
||||
- Easy to implement
|
||||
|
@ -555,4 +556,49 @@ A collection of handy functions that operate on ~sequences~.
|
|||
|
||||
#+END_SRC
|
||||
- ~seq-min~, ~seq-max~
|
||||
* Episode 9 - Basics of Macros
|
||||
* Episode 9 - Introduction to Macros
|
||||
** What is a macro?
|
||||
- A macro is defined much like a function
|
||||
- It works on compile time
|
||||
- It returns a new expression as the return value
|
||||
- The compiler "expands" a macro by replacing the macro call with the return value of the macro
|
||||
- Different evaluation rule than functions
|
||||
+ Unlike function calls, the arguments to a macro will be passed to the macro as they are,
|
||||
without evaluation.
|
||||
- Macros vs inline functions
|
||||
|
||||
** How to define and expand a macro?
|
||||
- We can define a macro using ~defmacro~ form
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defmacro inc (val)
|
||||
(list #'1+ val))
|
||||
|
||||
(defmacro mydef (name val)
|
||||
(list 'setq (intern (concat "my-" (symbol-name name))) val))
|
||||
|
||||
(defmacro foo (val)
|
||||
(1+ val))
|
||||
#+END_SRC
|
||||
|
||||
- We can inspect the expansion process using the ~macroexpand~ function family.
|
||||
+ ~macroexpand~: Expands the macros until no macro exists in the top level forms
|
||||
+ ~macroexpand-all~: Expands the macros all the way down to the subforms
|
||||
+ ~macroexpand-1~: Expands the macro only for one level or cycle
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(macroexpand-1 '(inc 10))
|
||||
(macroexpand-1 '(mydef blah 20))
|
||||
(print (macroexpand-1 '(when (> 10 5) (print "something"))))
|
||||
|
||||
#+END_SRC
|
||||
|
||||
** Feedback or question
|
||||
- https://lxsameer.com
|
||||
- [[https://twitter.com/lxsameer][@lxsameer]] on Twitter
|
||||
|
||||
* Episode 10 - More on Macros
|
||||
** Quasiquotes aka back quote
|
||||
** ~declare~ form
|
||||
* Episode 11 - Common pitfalls of Macros
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue