aboutsummaryrefslogtreecommitdiff
path: root/moo.org
blob: b7000e9f84b0851a49194b39b555bd6ce19078d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#+PROPERTY: header-args:emacs-lisp :lexical t

Setting the property for the whole buffer to have lexical binding in emacs-lisp
source blocks. Lexical binding will hold when evaluating any source block where
no other ~:lexical~ header arg is present.

* Moo
:PROPERTIES:
:header-args:emacs-lisp+: :noweb-ref moo
:END:

noweb-ref will make all blocks under this heading expand with =<<moo>>=

#+begin_src emacs-lisp
  (+ x 3)
#+end_src

* Goo
:PROPERTIES:
:header-args:emacs-lisp+: :noweb yes
:header-args:emacs-lisp+: :var foo="bar"
:END:

turn noweb on so we interpret the =<<moo>>= syntax as code to expand
setting a var ~foo~ to the string "bar" to be used later.

** Poop

properties go down into the subtrees

#+begin_src emacs-lisp
  (let ((x 1))
    <<moo>>)
#+end_src

#+RESULTS:
: 4

*** Floppy
:PROPERTIES:
:header-args:emacs-lisp+: :noweb no
:END:

apparently continuing with the "+" pattern takes the no over the yes above
this will fail to expand moo.

#+begin_src emacs-lisp
  (let ((x 1))
    <<moo>>)
#+end_src

#+RESULTS:
: let: Symbol’s value as variable is void: <<moo>>

** Gah

Define a function with a free variable x.

#+begin_src emacs-lisp :results none
  (defun getx ()
    x)
#+end_src

Because ~x~ is lexically bound in this block, ~getx~ will error
since ~x~ is not a dynamic variable and isn't bound with indefinite scope.

#+begin_src emacs-lisp
  (let ((x 1))    ; ‘x’ is lexically bound.
    (getx))
#+end_src

#+RESULTS:
: Symbol’s value as variable is void: x

we can flip lexical binding off for the evaluation of this block and
the free variable ~x~ is bound when ~getx~ is evaluated.

#+begin_src emacs-lisp :lexical no
  (let ((x 2))    ; ‘x’ is dynamically bound
    (getx))
#+end_src

#+RESULTS:
: 2

** Bah
:PROPERTIES:
:header-args:emacs-lisp+: :var foo="baz"
:END:

overriding the variable in this subtree

#+begin_src emacs-lisp
  foo
#+end_src

#+RESULTS:
: baz

* Loo

#+begin_src emacs-lisp :noweb-ref defvars
  (defvar loo)
#+end_src

* Boo

#+begin_src emacs-lisp :noweb-ref defvars
  (defvar boo)
#+end_src

* Mama

#+begin_src emacs-lisp :noweb yes
  <<defvars>>
#+end_src