<br><br><div class="gmail_quote">On Mon, Jan 21, 2013 at 8:46 PM, Paul Davis <span dir="ltr"><<a href="mailto:paul.joseph.davis@gmail.com" target="_blank">paul.joseph.davis@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">In Erlang a list of integers in the range 0-255 is a string. </div></blockquote><div><br></div><div>No it's not - a list of integers in the range 0-255 is not a string - it's a list of integers</div>
<div>from 0-255 and nothing else - you don't  a clue what it represents.</div><div><br></div><div>Example:</div><div><br></div><div>> Ages = [65,66,67].</div><div>"ABC"</div><div><br></div><div>is a list of the ages (integers) at which many people become pensioners in Sweden - it's also three ascii characters codes for 'A' 'B' and 'C'.</div>
<div><br></div><div>All erlang knows is that this is a list of three integers it hasn't a clue what it means.</div><div><br></div><div>The shell prints this as "ABC" (this is a string literal representing the</div>
<div>integers [65,66,67])  This is because the shell prints a list of printable character codes as a string literal, ie it guesses that the intended meaning is as a list of character codes and prints it as a string to help you.</div>
<div><br></div><div>In this case the shell guessed wrong. It's a list of ages :-)</div><div><br></div><div>We can use io:format to change the printed representation </div><div><br></div><div>> io:format(" ~s ~w ~p~n", [Ages, Ages,Ages]).</div>
<div>ABC [65,66,67] "ABC"</div><div><br></div><div>Ages is a list of three integers.</div><div><br></div><div>/Joe</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">An easy test is to show that the value 256 changes the encoding into a list of integers:<div><br></div><div><div>> term_to_binary([1, 2, 3, 4, 256]).</div>

<div><<131,108,0,0,0,5,97,1,97,2,97,3,97,4,98,0,0,1,0,106>></div></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 21, 2013 at 1:38 PM, Steve Davis <span dir="ltr"><<a href="mailto:steven.charles.davis@gmail.com" target="_blank">steven.charles.davis@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The following appears to encode lists of integers as strings (?!?):<br>
<br>
Eshell V5.9.3  (abort with ^G)<br>
1> term_to_binary([1,2,3,4]).<br>
<<131,107,0,4,1,2,3,4>><br>
<br>
Is there a reason for this that I'm missing?<br>
<br>
regs,<br>
/s<br>
<br>
_______________________________________________<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" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br>