Summing a number to the terms of a list

Bengt Kleberg Bengt.Kleberg@REDACTED
Tue Aug 12 16:48:41 CEST 2003


Jilani Khaldi wrote:

> Hi All,
>
> Why this code gives me these different results?
>
...deleted

>
> Results:
>
> A=[1,2,3].
> sumit:sum_me(A,100).
> "efg"
>
> sumit:sum_me(A,200).
> "\311\312\313"
>
> sumit:sum_me(A,300).
> [301,302,303] -- as I expected.
>
erlang uses lists of integers (in the range 0 - 255) to ''implement'' 
strings.
thus [101, 102, 103] is interpreted as the string "efg".
[201, 202, 203] are still characters, but not printable. so they are 
displayed as octal numbers in a string.
[301,302,303] has risen above the 255 limit and can not be a string. 
must be a list of numbers.


bengt




More information about the erlang-questions mailing list