mvellandi

mvellandi

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

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

Marked As Solved

tonyhammond

tonyhammond

Author of Exploring Graphs with Elixir

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.

Popular Prag Prog topics Top

New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
nicoatridge
Hi, I have just acquired Michael Fazio’s “Kotlin and Android Development” to learn about game programming for Android. I have a game in p...
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New

Other popular topics Top

AstonJ
Or looking forward to? :nerd_face:
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
AstonJ
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: The Ser...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New

Latest in PragProg

View all threads ❯