Exploring Graphs with Elixir by @tonyhammond: P.105, 107 — Ch 3 > Visualizing Graphs > Rendering with Graphviz
In making the water molecule and after writing a graph file using a variable, we’re told in 2 examples to print out the variable to inspect it using IO.puts
iex> with {:ok, dot} = Graph.to_dot(g) do
...> write_graph(dot, "dot/h2o.dot")
...> end
#GraphCommons.Graph<type: native, file: "...", data: "strict graph {\n...">
iex> IO.puts dot
strict graph {
"O"
"H"
"H"
"H" -- "O" [weight=1]
"H" -- "O" [weight=1]
}
:ok
Maybe it’s just me, but this produces a function dot/0 not found error.
The variable “dot” is probably no longer in scope after having performed the first operation.
To make it print, I moved the print command above write_graph/2 command like so:
iex> with {:ok, dot} = Graph.to_dot(g) do
...> IO.puts dot
...> write_graph(dot, "dot/h2o.dot")
...> end
(graph output...)
#GraphCommons.Graph<type: native, file: "...", data: "strict graph {\n...">