Guile Blocks: Fleshing out the Concept

This post is a continuation of a previous post and is meant to further showcase Guile Blocks, an Org Mode inspired implementation of source blocks in Guile Scheme.

This post will omit discussing the technical implementation. At present, documentation for Guile Blocks can be found in its README.

The source code for this page found here.

Graphs

Graphs can be created using gnuplot. You can either feed gnuplot raw data or generate the data from another block.

This graph is created by using a block containing space-delimited data:

set title 'Hello world!'
plot '-' with lines
1 1
2 2
3 3
4 4

Whereas this graph is created by running the following Ruby code with a gnuplot block in a pipeline:

def fibonacci(n)
   n <= 1 ? n :  fibonacci(n - 1) + fibonacci(n - 2)
end

10.times do |n|
  puts "#{n} #{fibonacci(n)}"
end

LaTeX

LaTeX snippets and equations are supported. These equations are converted to MathML using LaTeXML. If your browser does not support MathML, you may find odd behavior in this section.

Equations can be either simple or complex.

\frac{1}{2}
12
\oint \vec{E}\cdot \mathrm{d}\vec{A} =
\frac{q_{\mathrm{enc}}}{\varepsilon_0}
EdA=qencε0

Inline equations are also supported. For example, 54.

Like before, these equations can be quite complicated. For instance, here is a special case of the Schrödinger equation: itΨ(x,t)=[22m2x2+V(x,t)]Ψ(x,t).

Tables

Data can be formatted in the same style as Org-mode tables.

def fibonacci(n)
   n <= 1 ? n :  fibonacci(n - 1) + fibonacci(n - 2)
end

10.times do |n|
  puts "#{n} #{fibonacci(n)}"
end
Results:
| 0 |  0 |
| 1 |  1 |
| 2 |  1 |
| 3 |  2 |
| 4 |  3 |
| 5 |  5 |
| 6 |  8 |
| 7 | 13 |
| 8 | 21 |
| 9 | 34 |