Finish episode 5
This commit is contained in:
parent
67593cd35b
commit
a333e330a9
136
docs/videos.org
136
docs/videos.org
|
@ -152,7 +152,8 @@ CLOSED: [2022-03-12 Sat 18:38]
|
||||||
- How to define functions
|
- How to define functions
|
||||||
- vs macros
|
- vs macros
|
||||||
- vs special forms
|
- vs special forms
|
||||||
* Episode 4 - Conditionals
|
* DONE Episode 4 - Conditionals
|
||||||
|
CLOSED: [2022-04-09 Sat 11:24]
|
||||||
** What we learned so far
|
** What we learned so far
|
||||||
** what is true and what's not
|
** what is true and what's not
|
||||||
** Let & prog family
|
** Let & prog family
|
||||||
|
@ -176,3 +177,136 @@ CLOSED: [2022-03-12 Sat 18:38]
|
||||||
- boundp
|
- boundp
|
||||||
- More at https://www.gnu.org/software/emacs/manual/html_node/elisp/Type-Predicates.html
|
- More at https://www.gnu.org/software/emacs/manual/html_node/elisp/Type-Predicates.html
|
||||||
** type-of
|
** type-of
|
||||||
|
* Episode 5 - Lists
|
||||||
|
** What is a list?
|
||||||
|
- Not a primitive type
|
||||||
|
- A linked list made out of cons cells
|
||||||
|
|
||||||
|
** Cons Cells
|
||||||
|
- A container for pairs
|
||||||
|
- CAR
|
||||||
|
- CDR (could-er)
|
||||||
|
#+NAME: ep-5-cons
|
||||||
|
#+BEGIN_SRC graphviz-dot :file /tmp/cons.svg :cmdline -Kdot -Tsvg
|
||||||
|
digraph {
|
||||||
|
graph [bgcolor=transparent]
|
||||||
|
fontcolor="gray80"
|
||||||
|
node [color=gray80 shape="box", fontcolor="gray80"]
|
||||||
|
edge [color=gray80]
|
||||||
|
rankdir = "LR"
|
||||||
|
|
||||||
|
subgraph cluster_0 {
|
||||||
|
label="Cell"
|
||||||
|
color="gray80"
|
||||||
|
|
||||||
|
graph [bgcolor=transparent, fontcolor="gray80"]
|
||||||
|
node [color=gray80 shape="box", fontcolor="gray80"]
|
||||||
|
a0[label="car: 'head"]
|
||||||
|
b0[label="cdr: 'tail"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+RESULTS: ep-5-cons
|
||||||
|
[[file:/tmp/cons.svg]]
|
||||||
|
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq x1 (cons 'head 'tail))
|
||||||
|
(car x1)
|
||||||
|
(cdr x1)
|
||||||
|
|
||||||
|
'(head . tail)
|
||||||
|
(cons 2 nil)
|
||||||
|
(cons 1 x1)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+NAME: ep-5-list
|
||||||
|
#+BEGIN_SRC graphviz-dot :file /tmp/list.svg :cmdline -Kdot -Tsvg
|
||||||
|
digraph {
|
||||||
|
graph [bgcolor=transparent]
|
||||||
|
fontcolor="gray80"
|
||||||
|
node [color=gray80 shape="box", fontcolor="gray80"]
|
||||||
|
edge [color=gray80]
|
||||||
|
rankdir = "LR"
|
||||||
|
|
||||||
|
subgraph cluster_0 {
|
||||||
|
label="Cell"
|
||||||
|
color="gray80"
|
||||||
|
graph [bgcolor=transparent, fontcolor="gray80"]
|
||||||
|
node [color=gray80 shape="box", fontcolor="gray80"]
|
||||||
|
a0[label="car: 1"]
|
||||||
|
b0[label="cdr: "]
|
||||||
|
}
|
||||||
|
subgraph cluster_1 {
|
||||||
|
label="Cell"
|
||||||
|
color="gray80"
|
||||||
|
node [color=gray80 shape="box"]
|
||||||
|
a1[label="car: 2"]
|
||||||
|
b1[label="cdr: "]
|
||||||
|
b0 -> a1
|
||||||
|
}
|
||||||
|
subgraph cluster_2 {
|
||||||
|
label="Cell"
|
||||||
|
color="gray80"
|
||||||
|
node [color=gray80 shape="box"]
|
||||||
|
a2[label="car: 3"]
|
||||||
|
b2[label="cdr: nil"]
|
||||||
|
b1 -> a2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+RESULTS: ep-5-list
|
||||||
|
[[file:/tmp/list.svg]]
|
||||||
|
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq x2 (cons 1 (cons 2 (cons 3 nil))))
|
||||||
|
(setq x3 (list 1 2 3))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Some useful functions
|
||||||
|
- add-to-list
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq x4 (list 1 2 3 4))
|
||||||
|
(add-to-list 'x4 3)
|
||||||
|
(add-to-list 'x4 6)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- push & pop
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq x5 (list 1 2 3 4))
|
||||||
|
(push 1 x5)
|
||||||
|
(pop x5)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- member
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq x6 (list 'a 'b 1 2))
|
||||||
|
(member 'z x6)
|
||||||
|
(member 1 x6)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- delete
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq x7 (list 1 2 3 4 5))
|
||||||
|
(delete 3 x7)
|
||||||
|
x7
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- remove
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq x8 (list 1 2 3 4 5))
|
||||||
|
(remove 3 x8)
|
||||||
|
x8
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- car
|
||||||
|
- cdr
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq x9 (list 1 2 3 4))
|
||||||
|
(car x9)
|
||||||
|
(cdr x9)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
* Episode 6 - Property & Association Lists
|
||||||
|
|
Loading…
Reference in New Issue