Skip to content

markdown as an accessible, literate programming language¤

death to psuedocode, long live psuedocode.

%%html
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen="" frameborder="0" height="315" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/rmgJ5oNxQDA?si=xSpkJS5-fRSKcmok" title="YouTube video player" width="560"></iframe>
%% 
these are links we collected talking about calligraphy and code.

        links = Series\
- [patron saint of yak shaves](https://yakshav.es/the-patron-saint-of-yakshaves/)
- [quanta magazine: The Computer Scientist Who Cant Stop Telling Stories](https://www.quantamagazine.org/computer-scientist-donald-knuth-cant-stop-telling-stories-20200416/)
- [literate programming](http://www.literateprogramming.com/knuthweb.pdf)
- [Understanding Computer Programming as a Literacy](https://licsjournal.org/index.php/LiCS/article/view/794/609)
- [science vs literature](#)
- [the letter s](https://gwern.net/doc/design/typography/1980-knuth.pdf)
- [the unravelled calligram - foucault](https://monoskop.org/images/9/99/Foucault_Michel_This_Is_Not_a_Pipe.pdf)

> There is, finally between science and literature, a third margin which science must reconquer, that of pleasure.

My hope is that the ability to make explanations more nat- ural will cause more programmers to discover the joys of literate programming, because I believe it’s quite a pleasure to combine verbal and mathematical skills; but perhaps I’m hoping for too much.
![](https://i.pinimg.com/736x/cb/51/33/cb5133c2406fd5ee52b9cc437a618174.jpg)
calligraphy by [herman zapf](https://en.wikipedia.org/wiki/Hermann_Zapf)

live code¤

def to_vars(row):
    return pipe(
        {"index": row.name} | dict(row),
        dict.items,
        map("--%s: %f;".__mod__), " ".join)
%%
    df = DataFrame(index=Index(range(360), name="index"))
    df = df.assign(
        sin=(df.index * numpy.pi / 180).map(numpy.sin),
        cos=(df.index * numpy.pi / 180).map(numpy.cos),
    )

<style>
#dance {
    width: 50vw;
    tr {
        display: flex;
    }
    td, th {
        display: block;
        position: relative;
        transform: translateX(calc(var(--this) * 100%));
    }
}
</style>
<table id="dance">
<caption>waves</caption>
<thead>{% for column in list(df.index.names) + list(df.columns) %}<th>{{column}}</th>{% endfor %}</thead>
<tbody>{% for i, row in df.iterrows() %}<tr style="{{to_vars(row)}}">
<th>{{df.loc[i].name}}</th>
    {% for column in df.columns %}<td style="--this: var(--{{column}});">{{row.loc[column]}}</td>{% endfor %}
    </tr>{% endfor %}
    </tbody>
</table>
df = DataFrame(index=Index(range(360), name="index"))
df = df.assign(
    sin=(df.index * numpy.pi / 180).map(numpy.sin),
    cos=(df.index * numpy.pi / 180).map(numpy.cos),
)
waves
indexsincos
0 0.01.0
1 0.017452406437283510.9998476951563913
2 0.034899496702500970.9993908270190958
3 0.052335956242943830.9986295347545738
4 0.06975647374412530.9975640502598242
5 0.087155742747658170.9961946980917455
6 0.104528463267653460.9945218953682733
7 0.121869343405147480.992546151641322
8 0.139173100960065440.9902680687415704
9 0.156434465040230870.9876883405951378
10 0.173648177666930330.984807753012208
11 0.19080899537654480.981627183447664
12 0.207911690817759310.9781476007338057
13 0.2249510543438650.9743700647852352
14 0.241921895599667730.9702957262759965
15 0.258819045102520740.9659258262890683
16 0.275637355816999160.9612616959383189
17 0.292371704722736770.9563047559630354
18 0.30901699437494740.9510565162951535
19 0.325568154457156640.9455185755993168
20 0.34202014332566870.9396926207859084
21 0.358367949545300270.9335804264972017
22 0.3746065934159120.9271838545667874
23 0.39073112848927370.9205048534524404
24 0.406736643075800150.9135454576426009
25 0.422618261740699440.9063077870366499
26 0.43837114678907740.898794046299167
27 0.453990499739546750.8910065241883679
28 0.46947156278589080.882947592858927
29 0.484809620246337060.8746197071393957
30 0.499999999999999940.8660254037844387
31 0.51503807491005420.8571673007021123
32 0.52991926423320490.848048096156426
33 0.54463903501502710.838670567945424
34 0.55919290347074690.8290375725550416
35 0.5735764363510460.8191520442889918
36 0.58778525229247310.8090169943749475
37 0.60181502315204830.7986355100472928
38 0.61566147532565820.788010753606722
39 0.62932039104983740.7771459614569709
40 0.64278760968653930.766044443118978
41 0.65605902899050720.7547095802227721
42 0.66913060635885820.7431448254773942
43 0.68199836006249850.7313537016191706
44 0.69465837045899730.7193398003386512
45 0.70710678118654750.7071067811865476
46 0.71933980033865110.6946583704589974
47 0.73135370161917050.6819983600624985
48 0.74314482547739410.6691306063588582
49 0.7547095802227720.6560590289905073
50 0.7660444431189780.6427876096865394
51 0.77714596145697080.6293203910498375
52 0.7880107536067220.6156614753256583
53 0.79863551004729280.6018150231520484
54 0.80901699437494750.5877852522924731
55 0.81915204428899180.5735764363510462
56 0.82903757255504170.5591929034707468
57 0.83867056794542390.5446390350150272
58 0.8480480961564260.5299192642332049
59 0.85716730070211220.5150380749100544
60 0.86602540378443860.5000000000000001
61 0.87461970713939570.4848096202463371
62 0.88294759285892690.46947156278589086
63 0.89100652418836780.4539904997395468
64 0.8987940462991670.43837114678907746
65 0.90630778703664990.42261826174069944
66 0.91354545764260090.4067366430758002
67 0.92050485345244030.39073112848927394
68 0.92718385456678740.37460659341591196
69 0.93358042649720170.3583679495453004
70 0.93969262078590830.3420201433256688
71 0.94551857559931670.32556815445715676
72 0.95105651629515350.30901699437494745
73 0.95630475596303540.29237170472273677
74 0.96126169593831890.27563735581699916
75 0.96592582628906830.25881904510252074
76 0.97029572627599650.2419218955996679
77 0.97437006478523520.22495105434386492
78 0.97814760073380560.20791169081775945
79 0.9816271834476640.19080899537654492
80 0.9848077530122080.17364817766693041
81 0.98768834059513780.15643446504023092
82 0.99026806874157030.1391731009600657
83 0.9925461516413220.12186934340514749
84 0.99452189536827330.10452846326765346
85 0.99619469809174550.08715574274765814
86 0.99756405025982420.06975647374412546
87 0.99862953475457380.052335956242943966
88 0.99939082701909580.03489949670250108
89 0.99984769515639130.017452406437283376
90 1.06.123233995736766e-17
91 0.9998476951563913-0.017452406437283477
92 0.9993908270190958-0.03489949670250073
93 0.9986295347545738-0.05233595624294362
94 0.9975640502598242-0.06975647374412533
95 0.9961946980917455-0.08715574274765824
96 0.9945218953682734-0.10452846326765333
97 0.9925461516413221-0.12186934340514737
98 0.9902680687415704-0.13917310096006535
99 0.9876883405951377-0.15643446504023104
100 0.984807753012208-0.1736481776669303
101 0.981627183447664-0.1908089953765448
102 0.9781476007338057-0.20791169081775912
103 0.9743700647852352-0.2249510543438648
104 0.9702957262759965-0.24192189559966779
105 0.9659258262890683-0.25881904510252085
106 0.9612616959383189-0.27563735581699905
107 0.9563047559630355-0.29237170472273666
108 0.9510565162951536-0.30901699437494734
109 0.9455185755993168-0.3255681544571564
110 0.9396926207859084-0.3420201433256687
111 0.9335804264972017-0.35836794954530027
112 0.9271838545667874-0.37460659341591207
113 0.9205048534524404-0.3907311284892736
114 0.913545457642601-0.40673664307580004
115 0.90630778703665-0.42261826174069933
116 0.8987940462991669-0.4383711467890775
117 0.8910065241883679-0.4539904997395467
118 0.8829475928589271-0.46947156278589053
119 0.8746197071393959-0.484809620246337
120 0.8660254037844387-0.4999999999999998
121 0.8571673007021123-0.5150380749100543
122 0.8480480961564261-0.5299192642332048
123 0.8386705679454239-0.5446390350150271
124 0.8290375725550417-0.5591929034707467
125 0.819152044288992-0.5735764363510458
126 0.8090169943749475-0.587785252292473
127 0.7986355100472927-0.6018150231520484
128 0.788010753606722-0.6156614753256583
129 0.777145961456971-0.6293203910498373
130 0.766044443118978-0.6427876096865394
131 0.7547095802227718-0.6560590289905075
132 0.7431448254773942-0.6691306063588582
133 0.7313537016191706-0.6819983600624984
134 0.7193398003386514-0.694658370458997
135 0.7071067811865476-0.7071067811865475
136 0.6946583704589971-0.7193398003386512
137 0.6819983600624986-0.7313537016191705
138 0.6691306063588583-0.743144825477394
139 0.6560590289905073-0.754709580222772
140 0.6427876096865395-0.7660444431189779
141 0.6293203910498377-0.7771459614569707
142 0.6156614753256584-0.7880107536067219
143 0.6018150231520482-0.7986355100472929
144 0.5877852522924732-0.8090169943749473
145 0.5735764363510464-0.8191520442889916
146 0.5591929034707469-0.8290375725550416
147 0.544639035015027-0.8386705679454242
148 0.5299192642332049-0.848048096156426
149 0.5150380749100544-0.8571673007021122
150 0.49999999999999994-0.8660254037844387
151 0.48480962024633717-0.8746197071393957
152 0.4694715627858911-0.8829475928589268
153 0.45399049973954686-0.8910065241883678
154 0.4383711467890773-0.898794046299167
155 0.4226182617406995-0.9063077870366499
156 0.40673664307580043-0.9135454576426008
157 0.39073112848927416-0.9205048534524402
158 0.37460659341591224-0.9271838545667873
159 0.3583679495453002-0.9335804264972017
160 0.3420201433256689-0.9396926207859083
161 0.32556815445715703-0.9455185755993167
162 0.3090169943749475-0.9510565162951535
163 0.29237170472273705-0.9563047559630354
164 0.27563735581699966-0.9612616959383187
165 0.258819045102521-0.9659258262890682
166 0.24192189559966773-0.9702957262759965
167 0.22495105434386478-0.9743700647852352
168 0.20791169081775931-0.9781476007338057
169 0.19080899537654497-0.981627183447664
170 0.17364817766693028-0.984807753012208
171 0.15643446504023098-0.9876883405951377
172 0.13917310096006574-0.9902680687415703
173 0.12186934340514755-0.992546151641322
174 0.10452846326765373-0.9945218953682733
175 0.08715574274765864-0.9961946980917455
176 0.06975647374412552-0.9975640502598242
177 0.05233595624294381-0.9986295347545738
178 0.0348994967025007-0.9993908270190958
179 0.01745240643728344-0.9998476951563913
180 1.2246467991473532e-16-1.0
181 -0.017452406437283192-0.9998476951563913
182 -0.0348994967025009-0.9993908270190958
183 -0.052335956242943564-0.9986295347545738
184 -0.06975647374412483-0.9975640502598243
185 -0.08715574274765794-0.9961946980917455
186 -0.10452846326765305-0.9945218953682734
187 -0.12186934340514774-0.992546151641322
188 -0.13917310096006552-0.9902680687415703
189 -0.15643446504023073-0.9876883405951378
190 -0.17364817766693047-0.984807753012208
191 -0.19080899537654472-0.981627183447664
192 -0.20791169081775907-0.9781476007338057
193 -0.22495105434386498-0.9743700647852352
194 -0.2419218955996675-0.9702957262759965
195 -0.25881904510252035-0.9659258262890684
196 -0.275637355816999-0.9612616959383189
197 -0.2923717047227364-0.9563047559630355
198 -0.30901699437494773-0.9510565162951535
199 -0.32556815445715676-0.9455185755993167
200 -0.34202014332566866-0.9396926207859084
201 -0.35836794954530043-0.9335804264972017
202 -0.374606593415912-0.9271838545667874
203 -0.39073112848927355-0.9205048534524404
204 -0.4067366430757998-0.9135454576426011
205 -0.4226182617406993-0.90630778703665
206 -0.43837114678907707-0.8987940462991671
207 -0.45399049973954625-0.8910065241883681
208 -0.46947156278589086-0.8829475928589269
209 -0.48480962024633695-0.8746197071393959
210 -0.5000000000000001-0.8660254037844386
211 -0.5150380749100542-0.8571673007021123
212 -0.5299192642332048-0.8480480961564261
213 -0.5446390350150271-0.838670567945424
214 -0.5591929034707467-0.8290375725550418
215 -0.5735764363510458-0.819152044288992
216 -0.587785252292473-0.8090169943749476
217 -0.601815023152048-0.798635510047293
218 -0.6156614753256578-0.7880107536067222
219 -0.6293203910498376-0.7771459614569708
220 -0.6427876096865393-0.766044443118978
221 -0.6560590289905074-0.7547095802227719
222 -0.6691306063588582-0.7431448254773942
223 -0.6819983600624984-0.7313537016191706
224 -0.6946583704589974-0.7193398003386511
225 -0.7071067811865475-0.7071067811865477
226 -0.7193398003386509-0.6946583704589976
227 -0.7313537016191701-0.6819983600624989
228 -0.743144825477394-0.6691306063588585
229 -0.7547095802227717-0.6560590289905076
230 -0.7660444431189779-0.6427876096865395
231 -0.7771459614569711-0.6293203910498372
232 -0.7880107536067221-0.6156614753256581
233 -0.7986355100472928-0.6018150231520483
234 -0.8090169943749473-0.5877852522924732
235 -0.8191520442889916-0.5735764363510464
236 -0.8290375725550414-0.5591929034707472
237 -0.838670567945424-0.544639035015027
238 -0.848048096156426-0.529919264233205
239 -0.8571673007021121-0.5150380749100545
240 -0.8660254037844384-0.5000000000000004
241 -0.874619707139396-0.48480962024633684
242 -0.882947592858927-0.46947156278589075
243 -0.8910065241883678-0.4539904997395469
244 -0.8987940462991668-0.43837114678907774
245 -0.9063077870366497-0.42261826174069994
246 -0.913545457642601-0.4067366430758001
247 -0.9205048534524403-0.3907311284892738
248 -0.9271838545667873-0.3746065934159123
249 -0.9335804264972016-0.3583679495453007
250 -0.9396926207859082-0.3420201433256694
251 -0.9455185755993168-0.32556815445715664
252 -0.9510565162951535-0.30901699437494756
253 -0.9563047559630353-0.2923717047227371
254 -0.961261695938319-0.2756373558169989
255 -0.9659258262890683-0.25881904510252063
256 -0.9702957262759965-0.24192189559966779
257 -0.9743700647852351-0.22495105434386525
258 -0.9781476007338056-0.2079116908177598
259 -0.9816271834476639-0.19080899537654547
260 -0.984807753012208-0.17364817766693033
261 -0.9876883405951377-0.15643446504023104
262 -0.9902680687415704-0.13917310096006494
263 -0.9925461516413221-0.12186934340514717
264 -0.9945218953682734-0.10452846326765336
265 -0.9961946980917455-0.08715574274765825
266 -0.9975640502598242-0.06975647374412558
267 -0.9986295347545738-0.052335956242944306
268 -0.9993908270190957-0.03489949670250165
269 -0.9998476951563913-0.017452406437283498
270 -1.0-1.8369701987210297e-16
271 -0.99984769515639130.01745240643728313
272 -0.99939082701909580.03489949670250128
273 -0.99862953475457380.052335956242943946
274 -0.99756405025982430.06975647374412522
275 -0.99619469809174550.08715574274765789
276 -0.99452189536827340.10452846326765299
277 -0.9925461516413220.12186934340514768
278 -0.99026806874157040.13917310096006547
279 -0.98768834059513780.15643446504023067
280 -0.98480775301220810.17364817766692997
281 -0.98162718344766410.19080899537654425
282 -0.97814760073380580.20791169081775857
283 -0.97437006478523520.22495105434386492
284 -0.97029572627599660.24192189559966745
285 -0.96592582628906820.25881904510252113
286 -0.96126169593831880.2756373558169994
287 -0.95630475596303540.2923717047227367
288 -0.95105651629515360.30901699437494723
289 -0.9455185755993170.3255681544571563
290 -0.93969262078590850.34202014332566816
291 -0.93358042649720210.35836794954529955
292 -0.92718385456678740.37460659341591196
293 -0.92050485345244050.3907311284892735
294 -0.91354545764260080.40673664307580054
295 -0.90630778703664990.4226182617406996
296 -0.8987940462991670.4383711467890774
297 -0.8910065241883680.45399049973954664
298 -0.88294759285892710.4694715627858904
299 -0.87461970713939610.4848096202463365
300 -0.86602540378443860.5000000000000001
301 -0.85716730070211230.5150380749100542
302 -0.84804809615642620.5299192642332047
303 -0.83867056794542430.5446390350150266
304 -0.82903757255504210.5591929034707462
305 -0.81915204428899180.573576436351046
306 -0.80901699437494760.5877852522924729
307 -0.7986355100472930.6018150231520479
308 -0.78801075360672180.6156614753256585
309 -0.77714596145697080.6293203910498375
310 -0.76604444311897810.6427876096865393
311 -0.75470958022277220.656059028990507
312 -0.74314482547739460.6691306063588578
313 -0.7313537016191710.681998360062498
314 -0.71933980033865170.6946583704589966
315 -0.70710678118654770.7071067811865474
316 -0.69465837045899760.7193398003386509
317 -0.68199836006249830.7313537016191707
318 -0.66913060635885810.7431448254773942
319 -0.65605902899050740.7547095802227719
320 -0.64278760968653960.7660444431189778
321 -0.62932039104983780.7771459614569706
322 -0.61566147532565880.7880107536067216
323 -0.60181502315204830.7986355100472928
324 -0.58778525229247340.8090169943749473
325 -0.57357643635104650.8191520442889916
326 -0.55919290347074730.8290375725550414
327 -0.5446390350150270.838670567945424
328 -0.52991926423320580.8480480961564254
329 -0.51503807491005450.8571673007021121
330 -0.50000000000000040.8660254037844384
331 -0.48480962024633690.8746197071393959
332 -0.46947156278589080.8829475928589269
333 -0.453990499739546970.8910065241883678
334 -0.4383711467890770.8987940462991671
335 -0.42261826174070.9063077870366497
336 -0.406736643075800150.913545457642601
337 -0.39073112848927470.9205048534524399
338 -0.374606593415912350.9271838545667873
339 -0.358367949545300770.9335804264972015
340 -0.34202014332566860.9396926207859084
341 -0.325568154457157530.9455185755993165
342 -0.30901699437494760.9510565162951535
343 -0.292371704722736270.9563047559630357
344 -0.27563735581699980.9612616959383187
345 -0.25881904510252070.9659258262890683
346 -0.241921895599667870.9702957262759965
347 -0.224951054343865340.9743700647852351
348 -0.207911690817759870.9781476007338056
349 -0.190808995376544670.981627183447664
350 -0.173648177666931270.9848077530122079
351 -0.156434465040231120.9876883405951377
352 -0.139173100960065880.9902680687415703
353 -0.121869343405148110.992546151641322
354 -0.104528463267653420.9945218953682733
355 -0.087155742747658320.9961946980917455
356 -0.069756473744124760.9975640502598243
357 -0.052335956242944370.9986295347545738
358 -0.0348994967025008230.9993908270190958
359 -0.017452406437284450.9998476951563913
    def attrs(str):
        soup = __import__("bs4").BeautifulSoup(str, features="lxml")
        return soup.a.attrs | {"text": soup.a.string}
    links.apply(shell.tangle.parser.parser.render).apply(
        attrs
    ).series()
href text
0 https://yakshav.es/the-patron-saint-of-yakshaves/ patron saint of yak shaves
1 https://www.quantamagazine.org/computer-scient... quanta magazine: The Computer Scientist Who Ca...
2 http://www.literateprogramming.com/knuthweb.pdf literate programming
3 https://licsjournal.org/index.php/LiCS/article... Understanding Computer Programming as a Literacy
4 # science vs literature
5 https://gwern.net/doc/design/typography/1980-k... the letter s
6 https://monoskop.org/images/9/99/Foucault_Mich... the unravelled calligram - foucault
%%
we can save complex markdown objects as variables

        table_source=\
|    | href                                                                                               | text                                                                   |
|---:|:---------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------|
|  0 | https://yakshav.es/the-patron-saint-of-yakshaves/                                                  | patron saint of yak shaves                                             |
|  1 | https://www.quantamagazine.org/computer-scientist-donald-knuth-cant-stop-telling-stories-20200416/ | quanta magazine: The Computer Scientist Who Cant Stop Telling Stories |
|  2 | http://www.literateprogramming.com/knuthweb.pdf                                                    | literate programming                                                   |
|  3 | https://licsjournal.org/index.php/LiCS/article/view/794/609                                        | Understanding Computer Programming as a Literacy                       |
|  4 | #                                                                                                  | science vs literature                                                  |
|  5 | https://gwern.net/doc/design/typography/1980-knuth.pdf                                             | the letter s                                                           |



then we can recover the data from markdown and mark it useful without redundant work.

        pipe(
            table_source,
            shell.tangle.parser.parser.render,
            io.StringIO,
            pandas.read_html,
            first
        )
Unnamed: 0 href text
0 0 https://yakshav.es/the-patron-saint-of-yakshaves/ patron saint of yak shaves
1 1 https://www.quantamagazine.org/computer-scient... quanta magazine: The Computer Scientist Who Ca...
2 2 http://www.literateprogramming.com/knuthweb.pdf literate programming
3 3 https://licsjournal.org/index.php/LiCS/article... Understanding Computer Programming as a Literacy
4 4 # science vs literature
5 5 https://gwern.net/doc/design/typography/1980-k... the letter s

we can save complex markdown objects as variables

    table_source=\
href text
0 https://yakshav.es/the-patron-saint-of-yakshaves/ patron saint of yak shaves
1 https://www.quantamagazine.org/computer-scientist-donald-knuth-cant-stop-telling-stories-20200416/ quanta magazine: The Computer Scientist Who Can’t Stop Telling Stories
2 http://www.literateprogramming.com/knuthweb.pdf literate programming
3 https://licsjournal.org/index.php/LiCS/article/view/794/609 Understanding Computer Programming as a Literacy
4 # science vs literature
5 https://gwern.net/doc/design/typography/1980-knuth.pdf the letter s

then we can recover the data from markdown and mark it useful without redundant work.

    pipe(
        table_source,
        shell.tangle.parser.parser.render,
        io.StringIO,
        pandas.read_html,
        first
    )