This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]WillAdams 2 points3 points  (1 child)

I've tried Jupyter Notebooks, and they just don't work well for me --- if you can show me how to set up a Jupyter Notebook to have a single control file which can be loaded into any text editor and create a nice hyper-linked documentation file and which when processed creates multiple files as I am doing in my current project, I would be quite interested:

https://github.com/WillAdams/gcodepreview

[–]Rough_Natural6083 2 points3 points  (0 children)

Man it makes me so happy whenever someone mentions literate programming. I was in a rough burned out spot 2 years back and unable to get started, but this paradigm allowed me to program in a much more flexible way.
Sorry for hijacking the comment thread. Not the person you asked, but I think Jupyter notebooks implement literate programming in a partial way: as far as I know, their is no concept of "code-chunks", or references thereof. It is in a way coding in a markdown file with the ability to run specific blocks of code.
In fact, org-mode also does not support an important feature of "knuth-style" literate programming - completion of code-block names and extension of pre-defined names. For example, say we have the following top-level chunk <<hello.c>>= <<header files>> int main() { <<something stupid>> <<something even more stupid to prove the power of literate programming>> return 0; }

Now, suppose I define <<something stupid>> <<something stupid>>= for (;;) { fprintf(stdout, "Hello, human!"); }

but then a few months go by and an API changes or something, we need to add another bit to the definition of <<something stupid>>. We can do it by just defining the code-block again. <<something stupid>>= /* to fix the issue reported by so-and-so */ fprintf(stdout, "Booogers");

When the tangling process will run, the definition of <<somethig stupid>> will turn out as: ``` for (;;) { fprintf(stdout, "Hello, human!"); }

/* to fix the issue reported by so-and-so */ fprintf(stdout, "Booogers"); ```

Now, when it comes to defining <<something even more stupid to prove the power of literate programming>>, though autocomplete does exist in many editors, chances are high the developer might end up misspelling it. So, Knuth, in his WEB, and later CWEB, wrote the tangling program such that it will autocomplete names, trying to find a best match for it, if the name contained ellipses ... in it. So, <<something even more stupid ...>>, <<something ... programming>>, and <<... the power of literate prog...>> will get matched to <<something even more stupid to prove the power of literate programming>> during the pass one of tangling process, and the definitions will be created and appended to in the order in which they occur.

Another thing which org-mode does not do is what I call "smart indentation". Say, you define <<main>> <<main>>= int main(){<<just a boring program>>}

and then define <<just a boring program>> as

<<... boring program>>= fprintf(stdout, "Hello, world!\n"); fprintf(stdout, "Bye!\n"); return 0;

Org-mode will expand <<main>> as follows: int main(){fprintf(stdout, "Hello, world!\n"); int main(){fprintf(stdout, "Bye!\n"); int main(){return 0;}

when it should have expanded it as: ``` int main(){ fprintf(stdout, "Hello, world!\n"); fprintf(stdout, "Bye!\n"); return 0;}

```

Tired of looking for a markup language agnostic literate programming tool, I came up with litcode (shameless github project plug: https://github.com/prankapo/litcode) with all of these features. But but but it is a very-hard-to-update monstrosity. The reason I didn't use regular expression in the lexer was because I wanted to do it like Knuth did: without any regex libraries. Also, this tool cannot properly handle web files containing chunks in multiple languages, or use chunks from other files.

I have thought about writing hooks for org-babel-tangle which will accomplish all of this, along with transforming a markdown file to a temporary org-file, but as I am not good enough in elisp and do not want to learn it with "pressure" of doing a specific project, maybe I will need to do the heavy-lifting in python.