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.

Where Next?

Popular Pragmatic Bookshelf topics Top

simonpeter
When I try the command to create a pair of migration files I get an error. user=&gt; (create-migration "guestbook") Execution error (Ill...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |&gt; handle_event() |&gt; render() but the correc...
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
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

Other popular topics Top

axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1145 27688 760
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New
mindriot
Ok, well here are some thoughts and opinions on some of the ergonomic keyboards I have, I guess like mini review of each that I use enoug...
New

Sub Categories: