abhishek ranjan
abhishek ranjan

Reputation: 652

A roadblock working with erlang's List

I was working with list in erlang which is filled with a single value each time and I wanted to modify this list by multiplying its value with 10. But when I tried this the following thing happened:

 E=[4*10].
"("

I searched the ascii table and found that ascii value 40 is stored for the symbol "(" only. Can anybody trow some light on it and also tell me how I can get E=[40] by performing the multiplication inside the List only?

Upvotes: 0

Views: 45

Answers (1)

Asier Azkuenaga
Asier Azkuenaga

Reputation: 1189

Strings are represented as lists of bytes in Erlang and thus saying "(" it's exactly the same as [40].

It's just a syntactic sugar. Every time Erlang displays a list, if it contains "displayable" ASCII characters it will display the string instead of the list of numbers.

You can user format to control de display:

io:format("Number ~w is character ~c\n", [40 40]).

Upvotes: 1

Related Questions