String.Chars not implemented.

2,287 views
Skip to first unread message

Alex Shneyderman

unread,
Apr 11, 2014, 8:01:03 AM4/11/14
to elixir-l...@googlegroups.com
I am a bit confused by all the 

** (Protocol.UndefinedError) protocol String.Chars not implemented for Tunnel.Main.Parameters[verbose: true, hostname: "127.5.176.4", port: 29000, tunnels: 1, rate: 10]

Why can not elixir figure out how to print a record ? Do I have to defimp String.Chars, for: Tunnel.Main.Parameters ? Or is there a simpler way?

Cheers,

Alex

José Valim

unread,
Apr 11, 2014, 8:05:04 AM4/11/14
to elixir-l...@googlegroups.com
You need to `inspect value` or implement the protocol.



José Valim
Skype: jv.ptec
Founder and Lead Developer


--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Shneyderman

unread,
Apr 11, 2014, 8:14:02 AM4/11/14
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
IO.inspect params

produces 

08:12:17 goulash_client > ./ts_client --verbose --hostname=127.5.176.4 --port=29000

Tunnel.Main.Parameters[verbose: true, hostname: "127.5.176.4", port: 29000, tunnels: 1, rate: 10]

Tunnel.Main.Parameters[verbose: true, hostname: "127.5.176.4", port: 29000, tunnels: 1, rate: 10]

Why is it doubled ? I do use mix escriptize maybe that has something to do with the fact? 

Thanks,

Alex.

José Valim

unread,
Apr 11, 2014, 8:18:33 AM4/11/14
to elixir-l...@googlegroups.com
Note IO.inspect returns the given argument. This is very handy because you can insert it in the middle of a "pipeline" for example:

foo
|> do_this
|> IO.inspect
|> do_that

So it is doubled probably because you are printing and returning the value itself which cases it to be printed again.



José Valim
Skype: jv.ptec
Founder and Lead Developer


Reply all
Reply to author
Forward
0 new messages