Question

I wrote a simple functions to split an array to 2 parts.

split([], [], []) -> [[], []];
split([], [], Part2) -> [[], Part2];
split([], Part1, []) -> split([], [], Part1);
split([], Part1, Part2) -> [Part1, Part2];
split([Head | Tail], Part1, Part2) -> split(Tail, Part2, [Head | Part1]).

I tried to play with my function and I experienced a huge issue with that see the image below. The function works for a lot of example but if use for input [4,9,2],[],[] I got the following strange result ["\t",[2,4]].

enter image description here

Where is the issue? Thanks for your answer and time.

Was it helpful?

Solution

It is a behaviour of erlang:

8> [9].  
"\t"
9> ["\t"].
["\t"]

It is because, from erlang's POV, a string is just a series of number. erlang will try to print a number as a character if the number corresponds to a printable character.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top