Note that the atom '[]' represents the empty list [], and is therefore converted to the empty string.
Apart from error handling, this is a shorthand for
    text_to_string(Text, String) :-
	( Text == [] -> String = ""
	; atom(Text) -> atom_string(Text, String)
    	; string(Text) -> String = Text
	; is_list(Text), Text = [C|_], atom(C) -> string_chars(String, Text)
	; is_list(Text), Text = [C|_], integer(C) -> string_codes(String, Text)
	).
  Success:
    text_to_string([0'a,0'b,0'c],S)     % gives S=="abc".
    text_to_string([a,b,c],S)	        % gives S=="abc".
    text_to_string(abc,S)               % gives S=="abc".
    text_to_string("abc",S)             % gives S=="abc".
    text_to_string([],S)                % gives S=="".
  Fail:
    text_to_string(abc,abc)             % gives S=="abc".
  Error:
    text_to_string(T,S)                 % Error 4
    text_to_string([a,B,c],S)           % Error 4
    text_to_string([a,0'b,c],S)         % Error 5
    text_to_string(123,S)               % Error 5
    text_to_string([a,bb,c],S)          % Error 6
    text_to_string([97,-1,99],S)        % Error 6