# `pidgy` literate computing
you've heard of interactive computing, we'll call `pidgy` hyperactive computing.
<!--
```mermaidflowchart LR subgraph document language markdown end subgraph programming language IPython end subgraph templating language jinja2 end```
-->
<form id="controls">
<label for="run">🏃</label><button id="run" data-commandlinker-command="notebook:run-all-cells">run all</button>
<label for="doc">🖹</label><button id="doc" data-commandlinker-command="application:toggle-mode">document mode</button>
<label for="prez">📽</label><button id="prez" data-commandlinker-command="application:toggle-presentation-mode">presentation mode</button>
<label for="collapse">⊟</label><button id="collapse" data-commandlinker-command="notebook:hide-all-cell-code">collapse all the code</button>
<br/>
<label for="expand">⊞</label><button id="expand" data-commandlinker-command="notebook:show-all-cell-code">expand all the code</button>
<button data-commandlinker-command="deck:toggle"><code>jupyterlab-deck</code></button>
<button data-commandlinker-command="notebook:render-with-voila"><code>voila</code></button>
<label for="inspectoropen">🔍</label><button id="inspectoropen" data-commandlinker-command="inspector:open">inspector</button>
<label title="open side by side view" for="right">👯</label><button id="right" data-commandlinker-command="notebook:toggle-render-side-by-side-current">side-by-side</button>
</form>
> this presentation is written for the [february 2023 jupyter community call][community call].[^calls]
<button id="rara" data-commandlinker-command="runmenu:restart-and-run-all">restart and run all</button><label for="rara">or it didn't happen</label>
[^md]: there is massive adoption of markdown as a tool for programmers. folks can use markdown and jekyll templating languages on github pages. github profiles are written in markdown. markdown is a gateway drug to html, javascript, and css.
[community call]: https://hackmd.io/dcbps9AESEuP0N3j4mMOqw "hackmd for the jupyter community call"
[^calls]: jupyter community calls are a monthly series of events to showcase what you are doing in and with jupyter. please consider submitting to or hosting a [future community call] sometime
[future community call]: https://discourse.jupyter.org/t/jupyter-community-calls/668 "updating discourse announcement for the jupyter community calls."
[^md]: there is massive adoption of markdown as a tool for programmers. folks can use markdown and jekyll templating languages on github pages. github profiles are written in markdown. markdown is a gateway drug to html, javascript, and css.
[^calls]: jupyter community calls are a monthly series of events to showcase what you are doing in and with jupyter. please consider submitting to or hosting a
future community call
sometime
# my pidgy practices always have me indenting cells.# this habit means code will be rendered as code in markdown.# https://nbviewer.org/github/deathbeds/deathbeds.github.io/blob/master/deathbeds/2018-08-03-A-case-for-indented-code.ipynb# this is a presentation about pidgy so we start by loading the extension.# there is a pidgy kernel for the hardcore. # in that case we recommend the hybrid `.md.ipynb` extension.ifLITE:=(__import__("sys").platform=="emscripten"):# compatability for jupyterlite%pipinstallpandaspidgymatplotlibipywidgetstoolz# activate pidgy%reload_extpidgyfromtoolz.curriedimport*
## the `pidgy` polyglot metalanguage`pidgy` is a [pidgin] [metalanguage] of python programming and jinja templates embedded inside markdown.
literate programming is that aim to craft documentation and code at the same time.
literate computing is when we do this interactively, and weave live computing into the narrative.
[pidgin]: https://en.wikipedia.org/wiki/Pidgin
[metalanguage]: https://en.wikipedia.org/wiki/Metalanguage
pidgy
is a
pidgin
metalanguage
of python programming and jinja templates embedded inside markdown.
literate programming is that aim to craft documentation and code at the same time.
literate computing is when we do this interactively, and weave live computing into the narrative.
<figure><figcaption>theREPLoverlayedwitha[literatecomputing]workflowoftangleandweave.</figcaption>{%setrepl%}input[markdown]--tangle\nread-->IPythonIPython--eval/template-->jinjajinja--weave\nprint-->output[markdown]output[markdown]-.loop-.->inputhtml--->input;css--->input;javascript--->inputjulia--->magics;r--->magics;fortran--->magics;magics--->IPython{%endset%}```mermaidflowchartLR{%fori,lineinenumerate(repl.splitlines())%}{%ifi>extra.value%}%%{%endif%}{{line}}{%endfor%}```<figcaption>mermaidgraphsyntaxusesextendedmarkdownsyntaxprovidedby<code>jupyterlab-markup</code></figcaption></figure>display(extra:=IntSlider(6,min=1,max=6,description="show more languages"))# 6 lines in the graph`pidgy`isinterestedinexploringtheinterfacesoflanguagesincomputationalessays.eachlanguageprovidesextrasyntaxfortellingyourstory.withmarkdownwecanincludehtml,css,andjavascript;codeblockscanincludemorelanguageslikemermaid.[IPythonisourpolyglotgluelanguage][polyglotnotebook].[literatecomputing]:#[polyglotnotebook]:https://gist.github.com/fperez/5b49246af4e340c37549265a90894ce6"fperez's polyglot juypyter demo"[fperezlc]:https://web.archive.org/web/20220510083647/http://blog.fperez.org/2013/04/literate-computing-and-computational.html
## inspecting and doing more with a keypress
<label for="butt-inspector"><kbd>Ctrl + I</kbd></label>
<button id="butt-inspector" data-commandlinker-command="inspector:open">open inspector</button>
<label for="deck">⛔</label><button id="deck" data-commandlinker-command="deck:toggle"><code>jupyterlab-deck</code></button>
### translating markdown to python
the `%%tangle` magic tangles markdown to python code for previewing and debugging. this magic will help you learn `pidgy`s indenting [heuristics and language features provided by `midgy`][midgy basics].
[midgy basics]: https://deathbeds.github.io/midgy/language/basics/
<figure><figcaption>amermaidhomagetothedualusageoftheWEBfileformatbeingtranslatedtoadocumentandprogramminglanguage.</figcaption>```mermaidflowchartLRWEB--WEAVE-->TEX--TeX-->DVIWEB--TANGLE-->PAS--PASCAL-->REL```</figure><figuremarkdown><figcaption>knuth's rational for choosing Pascal; the same motivation applies to python.</figcaption>>IchosePASCALastheprogramminglanguagebecauseithasreceivedsuchwidespreadsupportfromeducationalin-stitutionsallovertheworld;itisnotmyfavoritelanguageforsystemprogramming,butithasbecomea"second language"forsomanyprogrammersthatitprovidesanexceptionallyeffectivemediumofcommunication.</figure>
### worrydream's cookies demo[^inventing]<!---![](https://media3.giphy.com/media/BsUORZkF3gBqg/giphy.gif"cookie monster happy as fuck eating cookies")---><blockquotecite="https://worrydream.com/Tangle/">[Tangle]isaJavaScriptlibraryforcreatingreactivedocuments.Yourreaderscaninteractivelyexplorepossibilities,playwithparameters,andseethedocumentupdateimmediately.Tangleissuper-simpleandeasytolearn.</blockquote><figure><figcaption>thesourcecodeforthefirst[TangleJs][tangle]demo</figcaption>```htmlWhenyoueat<spandata-var="cookies"class="TKAdjustableNumber">cookies</span>,youconsume<spandata-var="calories">calories</span>.``````javascriptvartangle=newTangle(document,{initialize:function(){this.cookies=3;},update:function(){this.calories=this.cookies*50;}});```</figure>[tangle]:http://worrydream.com/Tangle/[inventingonprinciple]:https://www.youtube.com/watch?v=PUv66718DII[^inventing]:manyfolksworkingoncomputationalinterfacesareinspiredbyBretVictor's [inventing on principle]
### live data in your document<detailsmarkdown><summary>importsforthepandasmatplotlibdemo</summary>importpandasfrompidgyimportget_cell_id%matplotlibagg</details><detailsmarkdownopen><summary>supportingmethodsfortheinteractivedemo</summary>`@functools.lru_cachedefget_gist(x,max=100):[gathergistfromthegithubapi][gist].returnpandas.read_json(F"https://api.github.com/users/{x}/gists?per_page={max}")[gist]:https://docs.github.com/en/rest/gists?apiVersion=2022-11-28deftidy_gist(x):explodethegistrepsonseintoadataframeofgistfilesgists=get_gist(x).set_index("id")returngists.files.apply(compose_left(dict.values,list)).explode().apply(pandas.Series).join(gists)</details>
#### an application in a cell.{%setgists=tidy_gist(_github_user.value)%}{%setlang=gists.language.dropna().value_counts()%}we've found information on {{gists.index.unique().shape[0]}} github gists, and {{len(gists)}} files, for @{{_github_user.value}}.inthiscollection,thereare{{len(lang)}}differentlanguagesincluded.theirmostcommonlanguageis{{lang.index[0]}}.{{gists.sample(2)}}display(_github_user:=Text("tonyfast"),button:=Button(description="submit"))button.on_click(lambdax,id=get_cell_id():print(id)orshell.weave.displays[id].update()){{lang.to_frame("ct").T}}
### et `voila`{%ifLITE%}>😞unforntunately,thispartofthedemoisnotavailableonjupyterlite.{%endif%}<buttondata-commandlinker-command="notebook:render-with-voila"{%ifLITE%}disabled{%endif%}>et<code>voila</code></button>
## wrap up*thispresentationhadanumberofincidentaldemos.*jupyterlab-deck*jupyterlab-markup*voila*mermaid*midgy*wehaveonandoffcellsnowthatallofthesourcesaremarkdown*thetemplatesyntaxisapowerfulwaytoincludepythonvariablesinline.thetraditionalnotebookformatonlyallowsforblocklevelliterateprograms.*sinceliterateprogramsarepidginlanguageswecan't expect them to be formalized. there are a lot of inconsistencies with the languages combined.jinja2templateimplementationsvary.markdownrenderersimplementationvary.pythonkeepsaddinglanguagefeatures.{%setsz=3%}{%seth=60%}<formstyle="font-size: {{sz}}rem; line-height: {{h}}%;"><labelfor="rara">🎗🎗🎗🎗🎗🎗🎗🎗</label><br/><buttonid="rara"data-commandlinker-command="runmenu:restart-and-run-all"style="font-size: {{sz}}rem; line-height: {{h}}%;">restartandrunall</button><br/><labelfor="rara">oritdidn't happen</label></form>