<div dir="ltr">Thank you,<div><br></div><div>I understand now.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 21, 2017 at 4:42 AM, Dmytro Lytovchenko <span dir="ltr"><<a href="mailto:dmytro.lytovchenko@gmail.com" target="_blank">dmytro.lytovchenko@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Because Erlang has no functions with variable amount of arguments (like for example in printf C/C++), args to io:format are passed as a list. So correct way to call it is:<div><br></div><div>io:format("Bla ~p~n", [Av1]).</div><div><br></div><div>Where ~p is to print any value, also there are more ways to format a value, consult the documentation page at <a href="http://erlang.org/doc/man/io.html#fwrite-1" target="_blank">http://erlang.org/doc/man/<wbr>io.html#fwrite-1</a></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">2017-02-21 10:15 GMT+01:00 Hakim Fajardo <span dir="ltr"><<a href="mailto:keam7095@gmail.com" target="_blank">keam7095@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">First, thank you because this is a great resource. <div><br></div><div>Second, I started writing basic programs every day to improve my Erlang coding. I wrote a simple program that calculates the average of a list of numbers. But I keep getting this error about io:format.</div><div><br></div><div><br></div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:menlo;font-size:9pt"><span style="background-color:rgb(52,65,52)">prices</span>([]) -><br> [],<br> io:format(<span style="color:rgb(106,135,89)">"List is empty ~n"</span>);<br><br><span style="color:rgb(128,128,128)">%% determine number of items in the list to calculate average%%<br></span><span style="color:rgb(128,128,128)"><br></span>prices(<span style="color:rgb(152,118,170)">L</span>) <span style="color:rgb(204,120,50);font-weight:bold">when </span>is_list(<span style="color:rgb(152,118,170)">L</span>) -><br> <span style="color:rgb(152,118,170)">Size </span>= length(<span style="color:rgb(152,118,170)">L</span>),<br> <span style="color:rgb(152,118,170)">Sum1 </span>= lists:sum(<span style="color:rgb(152,118,170)">L</span>),<br> <span style="color:rgb(152,118,170)">Av1 </span>= <span style="color:rgb(152,118,170)">Sum1 </span>/ <span style="color:rgb(152,118,170)">Size</span>,<br> io:format(<span style="color:rgb(106,135,89)">"The average equals ~n"</span>, <span style="color:rgb(152,118,170)">Av1</span>)<span style="color:rgb(204,120,50);font-weight:bold">.</span></pre></div><div><div><br></div><div>Then..</div></div><div><br></div><div><div>Eshell V8.2 (abort with ^G)</div><div>1> L = [1,2,2,2,3,3,4].</div><div>[1,2,2,2,3,3,4]</div><div><br></div><div>2> c(standev).</div><div>{ok,standev}</div><div><br></div><div>3> standev:prices(L).</div><div>** exception error: bad argument</div><div> in function io:format/3</div><div> called as io:format(<0.50.0>,"The average equals ~n",2.4285714285714284)</div></div><div><br></div><div><br></div><div>Why am I getting '**exception error:'?</div><div><br></div><div>Thank you, I hope this isn't too newbie a question.</div><div><br></div><div><br></div><div><br></div></div>
<br></div></div>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>