# Exploring Graphs with Elixir: Out of scope variable won't print (105, 107)

**URL:** <https://forum.devtalk.com/t/exploring-graphs-with-elixir-out-of-scope-variable-wont-print-105-107/9095>\
**Category:** PragProg Customers\
**Tags:** book-exploring-graphs-with-elixir, errata\
**Created:** [26 April 2021 12:14 UTC](https://forum.devtalk.com/t/exploring-graphs-with-elixir-out-of-scope-variable-wont-print-105-107/9095 "2021-04-26T12:14:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvellandi](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mvellandi/32/2726_2.png) [@mvellandi](https://forum.devtalk.com/u/mvellandi)\
**Post date:** [26 April 2021 12:14 UTC](https://forum.devtalk.com/t/exploring-graphs-with-elixir-out-of-scope-variable-wont-print-105-107/9095/1 "2021-04-26T12:14:07Z")

</div>

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

```auto
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:

```auto
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...">​

```

---

<div class="post-metadata">

**Author:** ![tonyhammond](https://forum.devtalk.com/user_avatar/forum.devtalk.com/tonyhammond/32/2769_2.png) [@tonyhammond](https://forum.devtalk.com/u/tonyhammond)\
**Post date:** [16 May 2021 13:45 UTC](https://forum.devtalk.com/t/exploring-graphs-with-elixir-out-of-scope-variable-wont-print-105-107/9095/2 "2021-05-16T13:45:29Z")

</div>

Thanks for the catch.

I fixed this by reading it back in from the file store, as so:

iex\> IO.puts read\_graph(“dot/default.dot”).data

In two places.

Should be in the next beta.
