Skip to content

Commit

Permalink
Describe computed diagram for factorial in preprocessor readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dragondive committed Jul 21, 2024
1 parent cac01a8 commit 3166a46
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/preprocessor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Fun and learning with the PlantUML preprocessor

The PlantUML preprocessor provides a higher level abstraction to generate the diagram
descriptions. It can also be used as a programming language to _compute_ the diagrams!

The preprocessor provides variables, conditional expressions, looping constructs, and
even functions, making it a full fledged Turing complete language.

This also enables having some fun while learning the preprocessor features. In this
document, I describe some such examples. **All of them are my original work.**

The example diagrams shown here are _computed_ by PlantUML, not manually described in
puml files.

1. **Compute factorial of a number**: uses and draws the recursion!

This _hacks_ a state diagram to denote the recursive calls and the computed
factorial value for each number. The `!function` feature defines the factorial
function that computes the factorial, creates the states and draws the connections
between the states.

https://github.com/dragondive/plantuml_demo/blob/bfd3b1c018fe5893a8f37a9a01a6d9e0074be6eb/src/preprocessor/factorial_demo.puml#L1-L31

![State Diagram hack showing factorial computation](diagrams/factorial_demo.svg)

0 comments on commit 3166a46

Please sign in to comment.