Literate Programming in Org Mode

Literate Programming in Org Mode

July 18, 2024 | emacs, example

tags
Emacs

Literate Programming CS #

  • C-c C-,: select template
  • C-c C-c: evaluate code inside source block

UML diagrams with PlantUML #

Python #

:results value #

Only if you use the header argument :results value the code of the block is wrapped by a function and the result of the code block is the return value of that function.

return 7 + 7
14

:results output #

On the other hand * means that the code of the block is sent to the interpreter. The result of the code block is what the code prints to the standard output.

print (f"7+7")
7+7
print("Welcome")
Welcome

with virtualenv #

(pyvenv-workon "tawakkalna_env")
echo $VIRTUAL_ENV
which python
import sys
print('\n'.join(sys.path))

Math #

literate-calc-mode #

github

  • C-Spc i
    • x literate calc evaluate line
    • “:results” dictionary or property list evaluation in org mode output/value
    • “:vars” dictionary or property list :var a=38 b=4 can be passed to the source block
Flour = 500g
Water = 100g
total = Flour + water

Calc mode #

  • C-Spc i

    • i : calc
    • q: quick calculator result of calculation will be stored in kill ring
    3 + 7 * (5 - 2)
    

OCR of Images #

arrows.png #

Bob Alice Red A - > - < - - - - - - Y - Bob Alice Red


Links to this note