views:

84

answers:

1

I am new to Erlang, and I am learning ETS. I have run into a weird problem. I did:

Sometab = ets:new(sometable, [bag]).
ets:insert(Sometab, {109, ash, 8}).

Then I typed:

ets:match(Sometab, {109, ash, '$1'}).

However instead of getting 8 - I am getting: ["\b"] as output! What am I doing wrongly?

+4  A: 

You are getting the correct answer. However, the erlang shell prints [8] as "\b" since the ascii code for backspace is 8.

Erlang has no string type. Strings in erlang are represented simply as a list of integers and the Erlang shell prints this list as a string if the list contains integers withing the ascii range only.

This can indeed be confusing at times.

Jonas
Oh! So when I pass this as output to say, a browser, it will be displayed fine then?
Well, yes... sort of. ["\b"] is the same thing as [[8]]. So if you want to get to the integer you can do something like [[X]] = ["\b"]. Now X will contain the integer 8.
Jonas