Creating Mind Maps in Racket
1 Mind Map Language
2 API
read-thoughts
thoughts->digraph-data
thoughts->pict
in-thoughts
exn:  fail:  mind-map:  indent
3 raco mind-map
4 Project Information
8.12

Creating Mind Maps in Racket🔗ℹ

Sage Gerard

 (require mind-map) package: mind-map

Use this collection to leverage a form of note-taking with indented lines. Here, a mind map is a text document where each line is an idea. Each idea may be indented to illustrate a composition of ideas.

    Machine Learning

      To Evaluate

        ELKI

        TensorFlow

          https://www.tensorflow.org

      Desired approaches

        Supervised

        Reinforcement

You cannot escape a line break to combine lines. This is deliberate, because this format is not meant for writing complete sentences or paragraphs.

Here, To Evaluate and Desired approaches belong to the Machine Learning idea. Although the example suggests otherwise, you can have more than one top-level idea in a document.

A line supports a leading mix of tabs and spaces, but an indentation error will occur if a scope cannot be inferred for a line. The rules for indentation imitate Python’s, such that a line with a lower level of indentation is expected to have the same number of tabs and spaces as a prior line in the same implied scope. See exn:fail:mind-map:indent.

1 Mind Map Language🔗ℹ

Write #lang mind-map at the top of the previous example. Save it as "example.rkt", then require it in a REPL. You will get a thoughts identifier bound to a list. That list represents the parse tree of a mind map.

> (require "example.rkt")

> thoughts

'(("Machine Learning" ("To Evaluate" ("ELKI") ("TensorFlow" ("https://www.tensorflow.org"))) ("Desired approaches" ("Supervised") ("Reinforcement"))))

In DrRacket, you can render thoughts as a pict.

(thoughts->pict thoughts)

2 API🔗ℹ

procedure

(read-thoughts in)  list?

  in : input-port?
Consumes all text from the input port and returns a list representing a parse tree of notes.

Any trailing or leading whitespace is trimmed from a line.

This assumes there is no leading #lang line.

If a line has an indentation error, read-thoughts will raise exn:fail:mind-map:indent.

procedure

(thoughts->digraph-data thoughts)  
list? list?
  thoughts : list?
Returns two lists of directed graph data. The first list contains vertices. The second contains edges.

An element of the vertex list is a pair. The car of the pair is a non-negative integer representing the vertex ID. The cdr of the pair is the string label for the vertex.

An element of the edge list is a pair of vertex IDs, such that the car’s vertex points to the cdr’s.

'((0 . "Machine Learning") (1 . "To Evaluate") (2 . "ELKI") (3 . "TensorFlow") (4 . "https://www.tensorflow.org") (5 . "Desired approaches") (6 . "Supervised") (7 . "Reinforcement")) '((5 . 7) (5 . 6) (0 . 5) (3 . 4) (1 . 3) (1 . 2) (0 . 1))

procedure

(thoughts->pict thoughts)  pict?

  thoughts : list?
Renders thoughts as a pict.

procedure

(in-thoughts thoughts)  sequence?

  thoughts : list?
Returns a 4-value sequence built from lazily traversing thoughts.

The values are as follows:

  1. The vertex ID (see thoughts->digraph-data) of a vertex, or #f.

  2. The string label of the vertex identified by value 1. If the first value is #f, then this value is also #f.

  3. The vertex ID of another vertex. Never #f.

  4. The string label of the vertex identified by value 3.

You interpret these values as a directed edge with vertex labels. The vertex identified by the first value points to the vertex identified by the third value. If the first two values are #f, that means no edges point to the vertex identified by the third value.

'((#f #f 0 "Machine Learning") (0 "Machine Learning" 1 "To Evaluate") (1 "To Evaluate" 2 "ELKI") (1 "To Evaluate" 3 "TensorFlow") (3 "TensorFlow" 4 "https://www.tensorflow.org") (0 "Machine Learning" 5 "Desired approaches") (5 "Desired approaches" 6 "Supervised") (5 "Desired approaches" 7 "Reinforcement"))

read-thoughts raises this exception for lines led by an invalid sequence of tabs or spaces.

lineno is one-based.

Consider the following document, where > represents a tab.

Trunk

  Branch

    Leaf

    Leaf

> Branch

  Branch

    Leaf

      Caterpillar

  Branch

The Branch with a leading tab raises an indentation error, because the transition from Leaf to Branch implies a change in scope, but there is no prior scope at Branch-level with the same leading whitespace.

The indentation error can be fixed by replacing the tab with a space, or by replacing one space with a tab in all indented lines.

3 raco mind-map🔗ℹ

The mind-map collection includes a raco command of the same name. The command will parse text files given as command line arguments and save the rendered mind maps to SVG files. Currently, any failure results in exit code 1.

$ raco mind-map path/to/mind-map.rkt path/to/notes.txt

As implied in the above command line, the input files do not have to be Racket modules. If the file starts with #lang mind-map, then it will be loaded as a Racket module. Otherwise it will be read as a plain text file using read-thoughts.

By default, the command will render the SVG documents in a mind-maps-out directory, relative to the command’s working directory. You can override this directory with --dest.

$ raco mind-map --dest other-dir ...

The command will not overwrite any files unless forced. Set -f or --force to overwrite any conflicting files.

By default, the command will print its activity on STDOUT. Use --quiet or -q to suppress STDOUT messages.

Run raco mind-map -h to review these options.

4 Project Information🔗ℹ

Source Code: https://github.com/zyrolasting/mind-map

Thanks to Hadi Moshayedi for use of the racket-graphviz package in thoughts->pict.