Summing a number to the terms of a list

Ulf Wiger (ÄL2/EAB) ulf.wiger@REDACTED
Tue Aug 12 16:58:08 CEST 2003


The shell guesses that the first two results are 
strings, as they are lists of numbers in the ASCII
range. The third list contains numbers greater than 
255, and is thus not formatted as a string.

This is a consequence of the fact that erlang lacks
a string data type. It's only a presentation issue.

Try e.g. io:format("~w~n", [sumit:sum_me(A,100)]).

/Uffe

-----Original Message-----
From: Jilani Khaldi [mailto:jilani.khaldi@REDACTED]
Sent: Tuesday, August 12, 2003 16:37
To: erlang-questions@REDACTED
Subject: Summing a number to the terms of a list


Hi All,

Why this code gives me these different results?

-module(sumit).
-export([sum_me/2]).

sum_me(H|T,X) -> [(H+X)|sum_me(T,X)];
sum_me([], X) -> [].

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.

jilani



More information about the erlang-questions mailing list